[英]Getting the value of a specific div inside a table row
我有一个动态表,其中包含数据库中的数据。 每行包含4个div元素,并带有一些文本。 我希望能够获得那些div之一的价值。
这是表格的一点:
function addData(Dato, BookedBy, Fra ,Til) {
var tbl = document.getElementById('bookingListe');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
// left cell
var cellLeft = row.insertCell(0);
var person = document.createElement("div");
var dato = document.createElement("div");
var fra = document.createElement("div");
var til = document.createElement("div");
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.name = "delete";
dato.innerHTML ="Booket for: " + Dato;
person.innerHTML ="Booket av: " + BookedBy;
fra.innerHTML ="Fra: " + Fra;
til.innerHTML ="Til: " + Til;
cellLeft.appendChild(person);
cellLeft.appendChild(dato);
cellLeft.appendChild(checkbox);
cellLeft.appendChild(til);
cellLeft.appendChild(fra);
这是获取这些div之一的方法。
function Slett(){
$('#bookingListe').find('tr').each(function () {
var row = $(this);
if (row.find('input[type="checkbox"]').is(':checked')){
alert(row.find('div').val());
// Since there are 4 divs, the code above isn't going to work
}
});
}
这行不通,而Javascript不是我的强项。 任何建议表示赞赏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.