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 に答える