[英]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.