所以我知道有一些關於此的帖子,但我沒有發現他們有幫助,所以我希望這會揭示我的問題。JQuery顯示覆選框表格行數據
我試圖從HTML表格中的複選框行中獲取數據。目前我只想在windows.alert
或Visual Studio控制檯上顯示它。但最終我會將數據發佈到數據庫。
我的代碼:
$(document).ready(function() {
$('#button').click(function() {
var id = [];
$(':checkbox:checked').each(function (i) {
id[i] = $(this).val();
});
if (id.length === 0) {
alert("Please select at least one checkbox");
}
else {
$.post('http://localhost/Dynamic/?Insert');
}
});
});
我試過alert($(this).text())
但只是顯示爲空。
幫助將不勝感激。
如果有幫助,這是我如何填充表:
var tableName = 'table1'
$.ajax({
url: 'http://localhost/Dynamic?prod=' + tableName,
dataType: 'Json',
success: function (Results) {
$.each(Results, function() {
var row = "";
for (i = 0; i < this.length; i++) {
var input = '<td>' + this[i] + '</td>';
row = row + input;
}
$('#table1 tbody:last-child').append('<tr>' + row + '<td> <input class="checkBox" type="checkbox" id="count"/> </td></tr>');
});
}
});
正如你可以看到表動態填充,因此它可以通過不同的表來填充。
不,它是正確的。我嘗試了冒號並且完全停止,只有冒號工作。 –
你的聲明在哪裏? – user3754008
在你的分配語句'code' id.push($(this).val()); '代碼' – user3754008