我有关于产品和价格的表格,我正在使用MVC模型获取数据,现在我尝试在我的图表上使用这些数据,但我无法从我的table.How获取数据,我可以获得吗?
这是表格的HTML代码
<tbody id="table2">
@foreach(var oge in Model)
{
<tr onclick="method(this)" data-toggle="modal" data-target="#mymodal">
<td id="product_name">@Html.Raw(oge.product_name)</td>
<td id="product_price">@Html.Raw(oge.product_price)</td>
</tr>
}
</tbody>
这是使用每个方法的jquery代码,注意:仅使用此表,页面上没有其他元素。
$("#button").click(function() {
$("td").each(function (index,value) {
alert(index + ": " + value);
}
);
});
执行代码后结果为;0:htmlCell...1:htmlcell...。。。
发布于 2018-08-31 23:47:06
如果您想使用value,可以使用value.innerText访问内容,但我同意上面建议使用$(this).text()的建议。
$("#table2 td").each(function (index,value) {
console.log(index + ": " + value.innerText);
console.log(index + ": " + $(this).text());
});
https://stackoverflow.com/questions/52118600
复制相似问题