【发布时间】:2018-08-31 15:26:23
【问题描述】:
我有关于产品和价格的表格,我正在使用 MVC 模型获取数据,现在我正在尝试在我的图形图表上使用这些数据,但我无法从表格中获取数据。我该如何获取?
这是表格的 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:html单元... 1:html单元... . . .
【问题讨论】:
-
机会
+ value到+ $(this).text() -
@RoryMcCrossan 一切正常,谢谢!
-
当你这样做时,
$('td')jquery 将选择所有td元素,当你使用each循环遍历它时,你会得到value中的每个td元素,当你这样做时alert它只会调用value.toString()并因此产生htmlCell。
标签: c# jquery html model-view-controller