0

こんにちは、次のテーブル出力行のデータがあります。各行の横に削除ボタンがあります。

           <form>
             <table id="tblAppendGrid" class="appendGrid">
                <thead class="ui-widget-header">
                <tbody class="ui-widget-content">
                <tr id="tblAppendGrid_Row_1">
                <td><input type="text" id="tblAppendGrid_s_1" name="nameCompany"    maxlength="100" style="width: 160px;"></td>
                <td><button id="tblAppendGrid_Delete_1" class="delete ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" value="2" type="text" title="Remove Current Row" tabindex="-1" role="button" aria-disabled="false"></td>
                <tr id="tblAppendGrid_Row_2">
               <td><input type="text" id="tblAppendGrid_s_2" name="nameCompany" maxlength="100" style="width: 160px;"></td>
               <td><button id="tblAppendGrid_Delete_2" class="delete ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" value="2" type="text" title="Remove Current Row" tabindex="-1" role="button" aria-disabled="false"></td>
           </tbody>
           <tfoot class="ui-widget-header">
           </table>
        </form>

削除ボタンがクリックされたときに行を読み込もうとしています。以下のコードのように、ボタン ID の横にある行番号を選択する方法がわかりません。そのため、機能していません。

      $(document).ready(function () {

           $("#tblAppendGrid_Delete_").button().click(function () {

                        testing("in delete");
                    });    
       });

セレクターは $("tblAppenDGrid_Delete_2") のようにする必要があると思います。...ボタンのクリックでこの行を選択して削除できるようにする方法を教えてください。ありがとう

4

1 に答える 1

0

ここには2つの問題があります

要素の ID は一意である必要があります。id を持つ要素が複数ありますtblAppendGrid_Delete_。この場合、クラス値を使用して、ID 属性の代わりにすべての削除ボタンをグループ化できます。

<button class="tblAppendGrid_Delete_1 delete ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" value="2" type="text" title="Remove Current Row" tabindex="-1" role="button" aria-disabled="false">

動的要素を扱っている可能性があるため、イベント委任ベースのイベント ハンドラーを使用する必要があります。

$(document).on('click', ".tblAppendGrid_Delete_", function () {
    testing("in delete");
});
于 2013-11-02T10:13:42.857 に答える