【问题标题】:Set th width after table refresh 10 sec on th resize column? [duplicate]在调整大小列的表刷新 10 秒后设置宽度? [复制]
【发布时间】:2018-11-15 09:10:53
【问题描述】:

我的问题是我的页面会在 10 秒后刷新,并且我已经添加了调整列大小的功能。

但在 10 秒后刷新页面后。表 th 回到原来的位置。

主要问题是我想如何在调整 th 后获得特定 th 的宽度并将该宽度应用于 th。

什么是 jquery 事件以在调整大小时获取宽度,以及什么方法只将宽度应用于其他人。以便用户在表格刷新后看到宽度大小。

div {
  resize: horizontal;
  overflow: auto;
  ;
}

td {
  text-align: center;
}
<div id="banner-message">
  <table cellpadding="0" cellspacing="0" border="0">
    <thead>
      <tr>
        <th>
          <div>One</div>
        </th>
        <th>
          <div>Two</div>
        </th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>ab</td>
        <td>cd</td>
      </tr>
    </tbody>
  </table>

</div>

【问题讨论】:

  • 您如何添加“调整列大小到th”的功能?那会给你答案。 (在杰克很好地为您更新您的问题之前添加了评论)
  • 使用css属性
  • 是的,用代码in问题,就可以看到了。您根本没有调整 th 的大小,而是在其中调整 div 的大小。捕捉该 div 的调整大小事件,存储宽度,重新绘制表格,重新应用存储的宽度。上面提供的关于如何捕捉 div 的调整大小事件的链接。
  • 仍然没有得到答案。有人说使用突变。我有错误..任何人都有完美的解决方案。

标签: javascript jquery html css


【解决方案1】:

您的主要问题是不知道用户设置的宽度。当您通过刷新或最初输入页面进入页面时,您会被默认值卡住。

保存这些值的一种方法是保存到add url parameters。然后get these values从url中确定要设置的宽度。另一种方法是使用localStoragesessionStorage。缺点是不能通过传递 url 来共享设置的宽度。 在detect that they have changed 之后更新值。

【讨论】:

    【解决方案2】:

    我得到了答案

    在th中添加了div元素

    <th><div>#</div></th>
    

    1.调整列大小

    $("#thead_DispatchTrip th").resizable({
            handles: "e",
            resize: function (event, ui) {
                $(ui.element).find('div').width(ui.size.width);
            }
        });
    

    2。获取宽度

    tableWidth = [];
        $("#thead_DispatchTrip th").each(function () {
            tableWidth.push($(this).find('div').width());
        });
    

    3。 10秒后设置宽度

    $("#thead_DispatchTrip th").each(function (i,el) {
        $(this).find('div').width(tableWidth[i]);
    });
    

    【讨论】:

      猜你喜欢
      • 2012-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-25
      • 2016-08-02
      • 2021-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多