2013-08-19 46 views
0

我想添加属性到没有标识或类的表头中。它拥有的只是现场。我的代码在这里不起作用。我感谢任何帮助将属性添加到没有标识或类的<th>

$(th[field = "item_group_ID"]).attr('hidden', 'true'); 

或者是否有任何其他方式,我可以做到这一点?继承人表

<table id="dg" title="jaiko pogi " class="easyui-datagrid" style="width:980px;height:370px;" 
     url="show_biochem.php" 
     toolbar="#toolbar" pagination="true" 
     rownumbers="false" fitColumns="true" singleSelect="true" height="auto";> 
    <thead> 
     <tr> 
     <th field="item_group_ID" width="8">ID</th> 
     </tr> 
    </thead> 
</table> 

解决了它。我阅读文档,并发现有一个功能。无论如何感谢您的帮助

$('#dg').datagrid('hideColumn','item_group_ID'); 

回答

0

您的选择不正确。它应该是一个字符串:

$('th[field="item_group_ID"]').attr('hidden', 'true'); 

另外,你是否试图隐藏元素?如果是这样,添加名为属性“隐藏”不会做..尝试这个:

$('th[field="item_group_ID"]').hide(); 
0

你缺少引号:

$("th[field='item_group_ID']").attr('hidden', 'true'); 

如果你想隐藏选定的元素改为使用.hide()函数。

+0

感谢。该函数现在执行但仍然无法执行任何操作。我在这里错过了什么? – raymond

+0

你想要做什么?如果你想隐藏元素,只需使用'.hide()'jQuery函数。 –

+0

尝试过,仍然不会隐藏。 http://www.jeasyui.com/demo/main/index.php这是我正在使用的一个。 – raymond

0

如果要使用不属于官方HTML语法(即field)的属性,则可以使用名为data-*(即data-field)的属性。所以:

<th data-field="item_group_ID" width="8">ID</th> 

来源:https://stackoverflow.com/a/1735268/1165203