Javascript 基于html属性的动态jquery选择器
我有以下代码:Javascript 基于html属性的动态jquery选择器,javascript,jquery,html,jquery-selectors,Javascript,Jquery,Html,Jquery Selectors,我有以下代码: <table id="Product"> <thead> <tr> <th>ProductId</th> <th>Productname</th> <th>Quantity</th>
<table id="Product">
<thead>
<tr>
<th>ProductId</th>
<th>Productname</th>
<th>Quantity</th>
<th>UnitPrice</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<button id="add" data-table="Product" data-url="Product/Add"></button>
我怎样才能得到桌子的主体
$('#add').click(function () {
var $this = $(this);
var url = $this.data("url");
var tableId = $this.data("table");
var $tableBody = $("#" + tableId + " tbody");
});
阅读有关jQuery选择器的更多信息,请访问
这里我用的是和
阅读有关jQuery选择器的更多信息,请访问
这里我用的是和。你说的表体是什么意思?哪个表?请检查新的详细信息
var tableBody=$(“table tbody”)
或var tableBody=$(“#”+table)
预期结果是什么?var tableBody=$(“#”+table+“tbody”);这个炒锅,$(“桌位体”)这个选择任何(或第一个)桌位标签。。。谢谢你说的桌身是什么意思?哪个表?请检查新的详细信息var tableBody=$(“table tbody”)
或var tableBody=$(“#”+table)
预期结果是什么?var tableBody=$(“#”+table+“tbody”);这个炒锅,$(“桌位体”)这个选择任何(或第一个)桌位标签。。。谢谢,这也适用于var tableBody=$(“#”+table+“tbody”);谢谢,这也适用于var tableBody=$(“#”+table+tbody”);
$('#add').click(function () {
var $this = $(this);
var url = $this.data("url");
var tableId = $this.data("table");
var $tableBody = $("#" + tableId + " tbody");
});
$('#add').click(function () {
var url = $(this).attr("data-url");
var table = $(this).attr("data-table");
var tableBody = $("#" + table).find("tbody");
//some logic with tablebody
});