2013-05-29 53 views
0

我使用Socket.IO加載了一些數據,並將它添加到Socket.io監聽器中的JS函數中。在該表的每一行末尾,我試圖添加一個按鈕,以獲取新添加的行中的內容並對其執行某些操作。但是,事件處理程序不會觸發新添加的按鈕。我覺得我正確地將on()附加到父母身上,並且嘗試過每一個變化,但我仍然無法讓按鈕觸發。這裏是我的代碼:將監聽器附加到Socket.IO中添加內容

$('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>   

我俯瞰一些與方式的socket函數工作的內部?

+0

你測試的是什麼瀏覽器? – lyxio

+0

我已經在Chrome和Firefox上測試過。 – Ristoph

回答

0

嘗試:

$('body').on('click', '.btn.btn-warning', function() { 
+0

工程!看起來這是選擇課程的不當方法。這樣一個小問題。感謝您指出! – Ristoph