【问题标题】:CSS, Javascript, XSL, Moving a row in a table to the bottom of the tableCSS, Javascript, XSL, 将表格中的一行移动到表格底部
【发布时间】:2021-11-22 18:10:17
【问题描述】:

我有一个正在处理的样式表,其中从样式表生成的 html 文件有一个切换按钮,用于将按钮在一行中、在表格中从勾号更改为十字。默认情况下,所有按钮都以选中(打勾)的形式出现……当单击按钮时,勾号变为十字形。我想要发生但不能做的是在单击时将整个行移动到表格的底部。最终结果是单击一行时,切换变为十字并移动到表格的底部。

感谢您的帮助

勾选/交叉码

/* Customize the label (the container) */
.customcheck {
  position: relative;
}

.customcheck input {
  display: none;
}

.customcheck input~.checkmark {
  background: #ee0b0b;
  width: 25px;
  display: inline-block;
  position: relative;
  height: 25px;
  border-radius: 2px;
  vertical-align:middle;
  margin-right:10px;
}

.customcheck input~.checkmark:after,
.customcheck input~.checkmark:before {
  content: '';
  position: absolute;
  width: 2px;
  height: 16px;
  background: #fff;
  left: 12px;
  top: 4px;
}

.customcheck input~.checkmark:after {
  transform: rotate(-45deg);
  z-index: 1;
}

.customcheck input~.checkmark:before {
  transform: rotate(45deg);
  z-index: 1;
}

.customcheck input:checked~.checkmark {
  background: #3d8a00;
  width: 25px;
  display: inline-block;
  position: relative;
  height: 25px;
  border-radius: 2px;
}

.customcheck input:checked~.checkmark:after {
  display: none;
}

.customcheck input:checked~.checkmark:before {
  background: none;
  border: 2px solid #fff;
  width: 6px;
  top: 2px;
  left: 9px;
  border-top: 0;
  border-left: 0;
  height: 13px;
  top: 2px;
}

....样式表条目....

<tr class="clickable">
          
<td>
<label class="customcheck">
  <input type="checkbox" checked="checked"/>
  <span class="checkmark"></span>
</label>
</td>

【问题讨论】:

  • 移动表格行的代码在哪里?
  • 嗨,这就是我需要的,另一种选择是使列可排序,我怎样才能使表格中的复选框列可排序?

标签: javascript css xslt checkbox


【解决方案1】:

使用appendChild 将点击labeltr 移动到其tbody 容器的底部:

document.querySelectorAll('tr.clickable').forEach(
  l => l.addEventListener(
         'click', 
         e => e.currentTarget.parentNode.appendChild(e.currentTarget)
       )
);
/* Customize the label (the container) */
.customcheck {
  position: relative;
}

.customcheck input {
  display: none;
}

.customcheck input~.checkmark {
  background: #ee0b0b;
  width: 25px;
  display: inline-block;
  position: relative;
  height: 25px;
  border-radius: 2px;
  vertical-align:middle;
  margin-right:10px;
}

.customcheck input~.checkmark:after,
.customcheck input~.checkmark:before {
  content: '';
  position: absolute;
  width: 2px;
  height: 16px;
  background: #fff;
  left: 12px;
  top: 4px;
}

.customcheck input~.checkmark:after {
  transform: rotate(-45deg);
  z-index: 1;
}

.customcheck input~.checkmark:before {
  transform: rotate(45deg);
  z-index: 1;
}

.customcheck input:checked~.checkmark {
  background: #3d8a00;
  width: 25px;
  display: inline-block;
  position: relative;
  height: 25px;
  border-radius: 2px;
}

.customcheck input:checked~.checkmark:after {
  display: none;
}

.customcheck input:checked~.checkmark:before {
  background: none;
  border: 2px solid #fff;
  width: 6px;
  top: 2px;
  left: 9px;
  border-top: 0;
  border-left: 0;
  height: 13px;
  top: 2px;
}
<table>
  <thead>
    <tr>
      <th>data</th>
      <th>action</th>
    </tr>
  </thead>
  <tbody>
    <tr class="clickable">
       <td>row 1</td>
       <td><label class="customcheck"><input type="checkbox" checked><span class="checkmark"></span></label></td>
    </tr><tr class="clickable">
       <td>row 2</td>
       <td><label class="customcheck"><input type="checkbox" checked><span class="checkmark"></span></label></td>
    </tr><tr class="clickable">
       <td>row 3</td>
       <td><label class="customcheck"><input type="checkbox" checked><span class="checkmark"></span></label></td>
    </tr><tr class="clickable">
       <td>row 4</td>
       <td><label class="customcheck"><input type="checkbox" checked><span class="checkmark"></span></label></td>
    </tr><tr class="clickable">
       <td>row 5</td>
       <td><label class="customcheck"><input type="checkbox" checked><span class="checkmark"></span></label></td>
    </tr><tr class="clickable">
       <td>row 6</td>
       <td><label class="customcheck"><input type="checkbox" checked><span class="checkmark"></span></label></td>
    </tr><tr class="clickable">
       <td>row 7</td>
       <td><label class="customcheck"><input type="checkbox" checked><span class="checkmark"></span></label></td>
    </tr><tr class="clickable">
       <td>row 8</td>
       <td><label class="customcheck"><input type="checkbox" checked><span class="checkmark"></span></label></td>
    </tr><tr class="clickable">
       <td>row 9</td>
       <td><label class="customcheck"><input type="checkbox" checked><span class="checkmark"></span></label></td>
    </tr><tr class="clickable">
       <td>row 10</td>
       <td><label class="customcheck"><input type="checkbox" checked><span class="checkmark"></span></label></td>
    </tr>
  </tbody>
</table>

【讨论】:

  • 谢谢你的代码完全按照我希望我的代码工作的方式工作,但我的代码仍然存在问题(没有向下移动)....但它肯定有助于我寻找我的问题
猜你喜欢
  • 1970-01-01
  • 2019-10-28
  • 2023-04-07
  • 1970-01-01
  • 2021-10-03
  • 2020-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多