Home > Web Front-end > JS Tutorial > jQuery toggle alternative method_jquery

jQuery toggle alternative method_jquery

WBOY
Release: 2016-05-16 15:09:56
Original
1660 people have browsed it

The specific content is as follows:

$('.back_left dt').toggle(function(){
$(this).addClass("selected");
$(this).siblings('dd').slideUp();
},function(){
$(this).removeClass("selected");
$(this).siblings('dd').slideDown();
}); 
Copy after login

I was working on a project today and copied a code from someone else’s website. I found that it couldn’t be implemented. When I was so anxious that I didn’t want to do it anymore, I thought, could it be a jquery version problem? Then I lowered the jquery version to 1.8 and the function was implemented. My own jqurey version is 1.11.1. It turned out to be a version problem. Once the reason was found, it was easy to solve. After searching on Baidu, I found that the toggle method was in version 1.9. It has been deleted. Changing the version can solve the problem, but I don't want to use the lower version anymore. I still want to use the 1.11.1 version. What method can I use to replace toggle?

After testing, you can use the following method instead:

$(document).ready(function(){ 
$('.back_left dt').click(function(){
if($(this).hasClass("selected")){
$(this).toggleClass("selected");
$(this).siblings('dd').slideDown();
}else{
$(this).toggleClass("selected");
$(this).siblings('dd').slideUp();
} 
}); 
});
Copy after login

Parameters Description
speed

Optional. Specifies how quickly an element goes from visible to hidden (or vice versa). Default is "0".

Possible values:

  • Milliseconds (e.g. 1500)
  • "slow"
  • "normal"
  • "fast"

With the speed set, the element will gradually change its height, width, margins, padding and transparency as it goes from visible to hidden.

如果設定此參數,則無法使用 switch 參數。

callback

可選。 toggle 函數執行完後,要執行的函數。

如需學習更多 callback 的內容,請造訪我們的 jQuery Callback 這一章。

除非設定了 speed 參數,否則不能設定該參數。

switch

可選。布林值。規定 toggle 是否隱藏或顯示所有被選元素。

  • True - 顯示所有元素
  • False - 隱藏所有元素

如果設定此參數,則無法使用 speed 和 callback 參數。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template