简体   繁体   English

jQuery 1.9和slideToggle的问题

[英]Issues with jQuery 1.9 and slideToggle

So, I'm not sure what happened, but I had his javascript function that shows/hides a div and then changes the + to a - when it's triggered. 所以,我不确定发生了什么,但我有他的javascript函数显示/隐藏div然后将+更改为 - 当它被触发时。

This is what I have: 这就是我所拥有的:

 $('.internal').hide();

$('.slider').click(function() {
    $(this).next('.internal').slideToggle();
}).toggle(function() {
    $(this).children("span").text("[-]");
}, function() {
    $(this).children("span").text("[+]");
    return false;
});

This apparently works great with jQuery's 1.8 library, but when I switch it to 1.9 or above it just slides everything up and makes everything dissapear. 这显然适用于jQuery的1.8库,但当我将其切换到1.9或更高时,它只是将所有内容都滑动并使一切消失。

Not too sure what happened or what was changed between 1.8 and 1.9 and I'm not sure what I need to fix to make it work again. 不太清楚发生了什么或者在1.8和1.9之间发生了什么变化,我不确定我需要修复什么才能让它再次发挥作用。

I made a fiddle: http://jsfiddle.net/9LcXk/ 我做了一个小提琴: http//jsfiddle.net/9LcXk/

Which is using 1.8.3 at the moment. 目前正在使用1.8.3。 But if you change it to 1.9 and re-run it, you'll see what happens. 但如果你将它改为1.9并重新运行它,你会看到会发生什么。

Use the click event instead: 请改为使用click事件:

DEMO DEMO

$('.slider').click(function () {
    $(this).next('.internal').slideToggle();
    this.toggle = !this.toggle;
    $(this).children("span").text(this.toggle ? "[-]" : "[+]");
    return false;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM