我有一个表格列,我试图扩展和隐藏。当我通过而不是通过元素<td>选择它时,jQuery 似乎隐藏了元素。class``name
<td>
class``name
例如:
$(".bold").hide(); // Selecting by class works. $("tcol1").hide(); // Selecting by name does not work.
请注意下面的 HTML。第二列name对所有行都相同。如何使用该name属性创建此集合?
name
<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>
您可以使用jQuery 属性选择器:
$('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'