我在我的项目中使用 Jquery 1.7。所以最近我升级到了jquery 2.1.4。
下面的代码现在不起作用,但之前的旧版本可以正常工作。 2.1.4 支持切换,请告诉我下面的代码有什么问题。
jQuery('#show-hide-filter-text').toggle(function(){
jQuery(this).text(hideTxt);
jQuery('#filterListDiv').slideDown("medium");
}, function(){
jQuery(this).text(showTxt);
jQuery('#filterListDiv').slideUp("medium");
});
最佳答案
toggle
的形式是 removed in jQuery 1.9 。您可以将其替换为简单的click
处理程序:
jQuery('#show-hide-filter-text').on("click", function() {
var $this = jQuery(this),
toggled = !!$this.data("toggled");
if (toggled) {
$this.text(showTxt);
jQuery('#filterListDiv').slideUp("medium");
} else {
$this.text(hideTxt);
jQuery('#filterListDiv').slideDown("medium");
}
$this.data("toggled", !toggled);
});
关于javascript - jquery 2.1.4 切换问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31530545/