jQuery实时事件中的切换问题 [英] Toggle Problem in live event of jquery
本文介绍了jQuery实时事件中的切换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我坚持下去,谁能帮助我...
I am stuck with this can anyone help me...
这是html
<tr class="appendvalue">
<td colspan="2">
<asp:DropDownList ID="ddlSource" runat="server"></asp:DropDownList>
<asp:TextBox ID="txtSourceValue" runat="server" CssClass="hide" />
<a href="#" class="t12">add static value</a>
</td>
这是jquery
$(document).ready(function() {
$('.appendvalue > td > a').live("click", function(e) {
e.preventDefault();
$(this).prev().prev().toggle();
$(this).prev().toggle();
$(this).toggle(function() { $(this).text("select from dropdown"); }, function() { $(this).text("add static value"); });
});
});
第一次单击后,它仅切换锚文本而不切换下拉列表和文本框.
after the first click it only toggles' the anchor text not toggling dropdown and textbox..
推荐答案
.toggle()实际上是单击事件的一种便捷方法,因此在同一元素的click事件处理程序中使用.toggle()会出现问题. .而是...
.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");
}
});
});
这篇关于jQuery实时事件中的切换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文