我可以輕鬆地趕上點擊複選框的事件的情況下,如下圖所示:不能趕上點擊HTML字符串的元素
<input type="checkbox" id="checkbox1" />
$('#checkbox1').change(function() {
if (this.checked) {
//Do stuff
}
});
在另一方面,我創建AJAX的回調複選框(jQuery的數據表)爲HTML和點擊同一元素的事件不能被獲取:
//...
"ajaxSource": "/Student/GetStudents",
"fnServerData": function (sSource, aoData, fnCallback) {
aoData.push({ "name": "all", "value": all });
$.getJSON(sSource, aoData, function (json) {
fnCallback(json);
$("div.toolbar").html('<input type="checkbox" id="checkbox1" /> Get all records');
});
},
什麼是最合適的方法來獲得在HTML字符串的複選框值?
您需要使用jQuery on()方法。 http://stackoverflow.com/questions/10082031/why-use-jquery-on-instead-of-click –