繁体   English   中英

隐藏显示表中的列

[英]hide column in display table

有什么办法可以隐藏显示表的列,我们有media =“ none”来隐藏列。我尝试使用

document.getElementById(display_column_name).media="none";

但它不起作用,我在设置javascript中显示列的attritube时卡住了。由于按钮选择列是隐藏/显示表的显示。

我在列标题上具有复选框。我必须隐藏显示表的列。单击按钮时隐藏选定的列。

我也尝试过使用div标签显示列

<div id= "col1" style="display:block">
            <display:column paramId="date_disp" paramName="date_disp"  property="date_disp" title="Date" sortable="true" headerClass="sortable" decorator="com.commons.ColDateDecorator" style="font-family:Arial, Helvetica, sans-serif;font-size: 12px;height: 25;"/>
</div>

和document.getElementById('col1')。style.display =“ none”; 但它不起作用。

是要隐藏的元素还是多个元素? document.getElementsByName将返回一个元素数组,因此您需要像这样访问它:

document.getElementsByName(display_column_name)[0] .media =“ none”

如果只是一个元素并且该元素具有ID,请考虑使用以下方法:

getElementById()

我也假设display_column_name是一个先前定义的变量,对吗?

最好的方法是将css显示样式设置为none。

document.getElementById("id _of_the_component").style.display = 'none';

或者,您可以使用jquery库,但必须从jquery.com下载jquery库。 使用script标签将脚本导入您的页面,然后执行以下操作

$("#id _of_the_component).hide();

请尝试以下操作:

HTML:

<html>
    <table>
        <tr>
            <td id="td1">TD1</td>
            <td id="td2">TD2</td>
            <td id="td3">TD3</td>
        </tr>        
    </table>
</html>

JavaScript:

document.getElementById("td2").style.display = "none";

演示: http//jsfiddle.net/Vishal_Suthar3/kDb8Z/

Uchenna是正确的,您可以使用jQuery库

使用脚本标记将脚本导入页面

向要隐藏的列添加属性“ id”或“ class”

并使用该类或ID可以隐藏该元素。

例如。 如果您具有提及的id属性,并且valuse为“ abc”

那么你可以写:

$(document).ready(function() 
{
$("#abc").hide();
});

修改显示列,例如:

<display:column class="abc" paramId="date_disp" paramName="date_disp"  property="date_disp" title="Date" sortable="true" headerClass="sortable" decorator="com.commons.ColDateDecorator" style="font-family:Arial, Helvetica, sans-serif;font-size: 12px;height: 25;"/>

在按钮上单击,您可以编写:可以说您正在使用按钮

<input type="submit" value="Submit" id="success" />
then you can use it like :

    $('#success').click(function(){
    $(".abc").hide();   
     });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM