0

Socket.IO を使用していくつかのデータをロードし、それを Socket.io リスナー内の JS 関数を使用してテーブルに追加しています。そのテーブルの各行の最後に、新しく追加された行のコンテンツを取得して何かを行うボタンを追加しようとしています。ただし、イベント ハンドラーは、新しく追加されたボタンに対して起動しません。親に適切にアタッチしていると感じ、on()これのすべてのバリエーションを試しましたが、まだボタンを起動できません。これが私のコードです:

$('body').on('click', '.btn btn-warning', function() {
    alert( $(this).text() );
});

socket.on('loadtable', function (table) {
            $("#tableBody").append('<tr><td>' + table["name"] + '</td><td>' + table["id"] +
            '</td><td>' + table["loc"] + '</td><td>' + table["area"] + '</td><td>' + table["zip"] +
             '</td><td><a href="#editModal" role="button" class="btn btn-warning" data-toggle="modal"><i class="icon-edit icon-white"></i></a>'
             + '</td><td><input type = "checkbox"></td></tr>'
            );
        });

<table class="table table-bordered table-hover" id ="jobsTable">

<thead>
    <tr>
        <th class = "span2">Name</th>
                    <th class = "span2">Process</th>
        <th class = "span2">JAR</th>
        <th class = "span1">Main Class</th>
        <th class = "span2">Args</th>
        <th class = "span1">Edit</th>
        <th class = "span1">Select</th>
    </tr>
</thead>

<tbody id = "tableBody">
</tbody>        

ソケット関数の内部で何かを見落としていますか?

4

1 に答える 1

0

試す:

$('body').on('click', '.btn.btn-warning', function() {
于 2013-05-29T23:49:03.040 に答える