【发布时间】:2015-11-12 16:01:19
【问题描述】:
我正在尝试引用变量 thisId 中 div 表行的 id。当我console.log(thisId) 时,它说thisId 是undefined。我做错了什么?
$('.deleteButton').click(function(){
var thisId = $(this).parent().parent().id;
for (var i = 0; i < tableData.length; i++) {
if (tableData[i].rowValue === thisId) {
tableData.splice(thisId, 1);
}
}
$(this).parent().parent().remove();
});
}
}
HTML
"<div id='" + tableData[i].rowValue + "' class=\"Row\">" +
"<div class=\"Cell\">" +
"<p>" + tableData[i].textInput + "</p>" +
"</div>" +
"<div class=\"Cell\">" +
"<p>" + tableData[i].perIntervalInput + "</p>" +
"</div>" +
"<div class=\"Cell\">" +
"<p>" + tableData[i].radioInput + "</p>" +
"</div>" +
"<div class=\"Cell\">" +
"<button class=\"deleteButton\">Delete</button>" +
"</div>" +
"</div>"
【问题讨论】:
-
这将引用的 HTML 在哪里?
-
.id是 DOM 元素的属性,而不是 jQuery。 -
.attr 或 .prop 似乎对我的问题没有帮助
-
@germz So
var thisId = $(this).closest('[id]')[0].id;或var thisId = $(this).closest('[id]').attr('id');或其他任何内容,但您的问题仍不清楚
标签: javascript jquery arrays