gpt4 book ai didi

javascript - jQuery 脚本不适用于更高版本

转载 作者:行者123 更新时间:2023-12-03 08:30:04 26 4
gpt4 key购买 nike

我有一个通过单击按钮来切换列表高度的脚本。问题是,它适用于 1.8.3 下的 jQuery。但是我的网站现在使用的是2.1.4,那么脚本有什么问题吗?

$(document).ready(function() {
var $dscr = $('#oplist'),
$switch = $('#opbutton'),
$initHeight = 100; // Initial height

if( $dscr.height() <= $initHeight ) {
$switch.hide();
}

$dscr.each(function() {
$.data(this, "realHeight", $(this).height()+20); // Create new property realHeight
}).css({ overflow: "hidden", height: $initHeight + 'px' });

$switch.toggle(function() {
$dscr.animate({ height: $dscr.data("realHeight") }, 100);
$switch.text('show less');
},
function() {
$dscr.animate({ height: $initHeight}, 100);
$switch.text('show all');
});
});

http://jsfiddle.net/68L0ho8q/

提前非常感谢您:)

最佳答案

https://api.jquery.com/toggle-event/

Note: This method signature was deprecated in jQuery 1.8 and removed in jQuery 1.9. jQuery also provides an animation method named .toggle() that toggles the visibility of elements. Whether the animation or the event method is fired depends on the set of arguments passed.

您现在需要实现自己的切换方法。

$switch.on("click", function () {
var isActive = !!$(this).data("active");
$(this).data("active", !isActive);
if (isActive) {
//active steps
} else {
//not active steps
}
});

关于javascript - jQuery 脚本不适用于更高版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33379599/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com