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(); });
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(); } }); });
Parameters | Description |
---|---|
speed |
Optional. Specifies how quickly an element goes from visible to hidden (or vice versa). Default is "0". Possible values:
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 是否隱藏或顯示所有被選元素。
如果設定此參數,則無法使用 speed 和 callback 參數。 |