3

我被这个困住了,任何人都可以帮助我......

这是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"); });
        });
    });

第一次点击后,它只切换'锚文本而不切换下拉和文本框..

4

2 回答 2

2

试试这个:

$(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"); });
    });
});
于 2010-01-30T07:40:22.043 回答
1

.toggle() 确实是点击事件的便捷方法,因此在同一元素的点击事件处理程序中使用 .toggle() 会出现问题。反而...

$(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");
        }
    });
});
于 2010-01-30T08:49:23.090 回答