Toggle Problem in live event of jquery

心不动则不痛 提交于 2019-12-06 01:22:54

.toggle() is really a convenience method for click events, so using .toggle() within the click event handler of the same element is going to be problematic. Instead...

$(document).ready(function() {
    $('.appendvalue > td > a').live("click", function(e) {
        e.preventDefault();
        $(this).prevAll().toggle();
        if ($(this).parent().find("input").is(":hidden")) {
            $(this).text("add static value");
        } else {
            $(this).text("select from dropdown");
        }
    });
});

Try this instead:

$(document).ready(function() {
    $('.appendvalue > td > a').live("click", function(e) {
        e.preventDefault();
        var $this = $(this);
        $this.prevAll().toggle();
        $this.toggle(function() { $this.text("select from dropdown"); }, function() { $this.text("add static value"); });
    });
});
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!