javascript - 我不想在拖动和排序时在行中包含列

标签 javascript jquery html asp.net-mvc-3

我在循环中从数据库中提取了下表。 我想拖放以下行。

“排序”按钮列的rowspan是动态的。 (这将是行数)。 我的问题是当我拖动行进行排序时,我不想包含“排序”按钮列。

enter image description here

拖动第一行后,“排序”按钮列已经随着拖动的行移动如下。

enter image description here

谢谢

最佳答案

语义不佳

这里的主要问题是您的保存按钮是表格的一部分。为什么? table 元素用于表示表格数据,按钮不是表格数据。

如果您的 HTML 具有更准确的语义,您就可以完全避免这个问题:

<!-- Section A -->
<section>
    <table>
        ...
    </table>
    <button>Save</button>
</section>

有了它,您就可以拖动行而不必担心您的 button 被包含在拖动中。您将有一个单独的 section 元素来包装每个相关的节表,并且 button 是独立的。

使用 CSS 我们可以将按钮的样式设置在我们希望它相对于表格的位置。第一步是将表格设置为 display: inline-table 以允许按钮位于其旁边。


演示

section {
  margin-bottom: 20px;
}

table {
  display: inline-table;
  vertical-align: top;
}

th, td {
  text-align: left;
}

button {
  vertical-align: bottom;
}
<section>
  <table>
    <thead>
      <tr>
        <th colspan="3">Section A</th>
      </tr>
      <tr>
        <th>Name</th>
        <th>Section</th>
        <th>Address</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>AA</td>
        <td>13</td>
        <td>SG</td>
      </tr>
      <tr>
        <td>BB</td>
        <td>16</td>
        <td>JP</td>
      </tr>
    </tbody>
  </table>
  <button>Save</button>
</section>

<section>
  <table>
    <thead>
      <tr>
        <th colspan="3">Section B</th>
      </tr>
      <tr>
        <th>Name</th>
        <th>Section</th>
        <th>Address</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>AA</td>
        <td>13</td>
        <td>SG</td>
      </tr>
      <tr>
        <td>BB</td>
        <td>16</td>
        <td>JP</td>
      </tr>
    </tbody>
  </table>
  <button>Save</button>
</section>

关于javascript - 我不想在拖动和排序时在行中包含列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30071298/

相关文章:

javascript - 在多个li的html中搜索一个字符串

php - 错误缺失;通过jquery发送序列化xml时jquery中的before语句

javascript - 如何将数字输入设置为 javascript 变量?

javascript - SWFupload url回调

javascript - 连接不会关闭 mongodb

javascript - 如何防止文本区域的事件冒泡,同时保持其可编辑性?

javascript - 使用 Jquery $.ajax() 以通用方式访问 json 对象

javascript - 如何使用 jquery 单击动态单元格值打开对话框

javascript - 在响应式网格中使用 slidetoggle 时如何防止其他 div 移动?

html - 制作自定义输入文本类型