如何使用 jQuery 按名称选择元素? [英] How can I select an element by name with jQuery?
问题描述
我有一个表格列,我想展开和隐藏.当我通过 I have a table column I’m trying to expand and hide. jQuery seems to hide the 例如: 注意下面的 HTML.第二列的所有行都具有相同的 Note the HTML below. The second column has the same 您可以使用 jQuery 属性选择器: 这篇关于如何使用 jQuery 按名称选择元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!class
而不是元素的 name
选择它时,jQuery 似乎隐藏了 元素.
<td>
elements when I select it by class
but not by the element’s name
.$(".bold").hide(); // Selecting by class works.
$("tcol1").hide(); // Selecting by name does not work.
name
.如何使用 name
属性创建此集合?name
for all rows. How could I create this collection using the name
attribute?<tr>
<td>data1</td>
<td name="tcol1" class="bold"> data2</td>
</tr>
<tr>
<td>data1</td>
<td name="tcol1" class="bold"> data2</td>
</tr>
<tr>
<td>data1</td>
<td name="tcol1" class="bold"> data2</td>
</tr>
推荐答案
$('td[name="tcol1"]') // Matches exactly 'tcol1'
$('td[name^="tcol"]' ) // Matches those that begin with 'tcol'
$('td[name$="tcol"]' ) // Matches those that end with 'tcol'
$('td[name*="tcol"]' ) // Matches those that contain 'tcol'
登录
关闭