【问题标题】:Styling Dynamically added table headers and columns样式化动态添加的表头和列
【发布时间】:2012-04-21 17:05:09
【问题描述】:

我需要通过更改 CSS 设置/样式来为动态添加到我的页面的表格设置样式。不知何故,这不起作用,我正在寻找解决这个问题的方法。如何为动态创建的表调整表头和列的大小?

【问题讨论】:

    标签: javascript jquery asp.net css


    【解决方案1】:

    查看 jquery .css()

    http://api.jquery.com/css/

    $("th").css( "width", value )
    

    Jquery 有一些函数可以动态改变 css 属性。还有一些宽度的函数

    $("th").width( value )
    

    http://api.jquery.com/width/

    在表格添加到页面后调用这些函数。

    【讨论】:

      【解决方案2】:

      如果表有 id 或类,您可以直接在 css 中定位它们。如果它们被覆盖,请为它们添加一个 !important 标记。

      table#idhere {width:500px !important}
      

      table.clashere {width:500px !important}
      


      这将找到表格的宽度,然后将其添加为属性,以便对其进行设置。

      var tableWidth = $('#tbl_reportview table.report').width();
      $('#tbl_reportview table.report').attr('width',tableWidth + 'px');
      

      【讨论】:

      • 我在 CSS 文件中指定了这个,但它似乎对我不起作用。 #tbl_reportview table.report{width:auto;}
      • 如果我理解你在问什么,上面的代码对你有用。
      猜你喜欢
      • 2012-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多