计算这个很长的 Jquery 语句
<table id="tb1" border="0" align="left" cellpadding="2" cellspacing="2" class="formTable" width="100%">
<tbody>
<tr>
<th class="coltextleft" colspan=3> seats </th>
<th>Total Seat Count : <span id="seats">0</span></th>
<th>SALC <input name="txt1" type="text" id = "txt1"></th>
<th>Column name </th> <th> <input name="id_reset" type="button" id="id_reset" value="RESET" ></th>
</tr>
<tr>
<td> </td>
<td id="zxx"> Col1</td>
<td> Col2</td>
<td> Col3</td>
<td> COL4</td>
<td>COL5</td>
<td>COL6</td>
</tr>
<tr id ="rnum_$i"><td>$i</td>
<td><input type="text" id="id_seats$i" name="seats[]"/></td>
<td>HTML ELEMENT OF TYPE SELECT </td>
<td>HTML ELEMENT OF TYPE TEXT</td>
<td>HTML ELEMENT OF TYPE TEXT</td>
<td>HTML ELEMENT OF TYPE TEXT</td>
<td>HTML ELEMENT OF TYPE TEXT</td>
<tr>
</tbody>
</table>
假设上面的 html 表有 5 行,并且有一个按钮“Addone row”,可以向表中添加一个新行。
var num = $('#id_seats1').parent().parent().parent().children().last().children().html()*1;
我如何计算上述 html 表的上述 Jquery 语句。该语句给出的输出是行数 出现在上面的 html 表中。您能否显示此语句的逐步执行
var num = $('#id_seats1').parent().parent().parent().children().last().children().html()*1;
请帮忙
<table id="tb1" border="0" align="left" cellpadding="2" cellspacing="2" class="formTable" width="100%">
<tbody>
<tr>
<th class="coltextleft" colspan=3> seats </th>
<th>Total Seat Count : <span id="seats">0</span></th>
<th>SALC <input name="txt1" type="text" id = "txt1"></th>
<th>Column name </th> <th> <input name="id_reset" type="button" id="id_reset" value="RESET" ></th>
</tr>
<tr>
<td> </td>
<td id="zxx"> Col1</td>
<td> Col2</td>
<td> Col3</td>
<td> COL4</td>
<td>COL5</td>
<td>COL6</td>
</tr>
<tr id ="rnum_$i"><td>$i</td>
<td><input type="text" id="id_seats$i" name="seats[]"/></td>
<td>HTML ELEMENT OF TYPE SELECT </td>
<td>HTML ELEMENT OF TYPE TEXT</td>
<td>HTML ELEMENT OF TYPE TEXT</td>
<td>HTML ELEMENT OF TYPE TEXT</td>
<td>HTML ELEMENT OF TYPE TEXT</td>
<tr>
</tbody>
</table>
Say for the above html table i have 5 rows and we have a button "Addone row " which adds up a new row to the table .
var num = $('#id_seats1').parent().parent().parent().children().last().children().html()*1;
How do i compute the above Jquery Statement for the above html table . The out put that this statement gives the number of rows of
that are present in the above html table . Can you please show step by step execution of this statement
var num = $('#id_seats1').parent().parent().parent().children().last().children().html()*1;
Please Help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将选择
元素。
这会选择
td
,然后是tr
,最后是tbody
元素。这选择 tbody 元素的最后一个子元素,它是一个
tr
这选择最后一行中所有
td
的 html 内容这转换最后一行的内容(这是一个包含该行中单元格的所有内容的字符串)转换为数字。
由于第一个单元格包含一个计数器
$i
变量,因此该值最终被分配给var num
This selects the
<input id='id_seats1'>
element.this selects the
td
, then thetr
, then thetbody
element.this selects the last child of the tbody element, which is a
tr
this selects the html contents of all the
td
s in that last rowthis converts the content of the last row (which is a string that contains all the contents of the cells in that row) into a number.
Since the first cell contains a counter
$i
variable, that is the value that winds up being assigned tovar num
jQuery 语句不会返回表中的行数,而是返回最后一个元素的子级 html 的数值等效内容。
用于查找表中总行数的 jQuery 片段应该是,
并且可以优化为,
但理想的解决方案是,
The jQuery statement will not return the number of rows in the table but the content of the last element's children's html's numerical equivalent.
The jQuery snippet to find the total number of rows in the table should've been,
and can be optimized as,
But the ideal solution would be,