javascript - 从许多选定的表格行到一个 div 标签

标签 javascript jquery html css jquery-ui

使用 jQuery 中的可选小部件,我制作了一个函数来选择表格中的行。现在我希望选定的行将一起形成一个 div 标签(不多,只有一个大 div)和 div 标签以便能够添加其他功能,如可拖动和可调整大小,如何做到这一点?

jsFiddle

jQuery("#wrapper>table>tbody").bind("mousedown", function(e) {
  e.metaKey = false;
}).selectable({
  filter: "td",
  stop: function( event, ui ) {
    jQuery( ".ui-selected").addClass('todiv');
  }
}); 

<div id="wrapper">
  <table>
    <col width="9%">
    <thead>
      <tr>
        <th colspan="2">&nbsp;</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th rowspan="2">&nbsp;</th>
        <td>&nbsp;</td>
      </tr>
      <tr> 
        <td>&nbsp;</td>
      </tr>
      <tr>
        <th rowspan="2">&nbsp;</th>
        <td>&nbsp;</td>
      </tr>
      <tr> 
        <td>&nbsp;</td>
      </tr>
    </tbody>
  </table>
</div>

table,th,tr,td { border: 1px solid black; }

.ui-selectable .ui-selected { background-color: #a6c9e2; }
.ui-selectable .ui-selecting { background: #FECA40; }

.todiv { background-color: green; }

最佳答案

你可以像这样克隆它们并放入一些容器中:

var selected = $('#wrapper .todiv');
$('#rowsContainer').empty().append(selected.clone());

但它们看起来不像表格中的行,如果需要,您需要为它们准备单独的样式。

JSFiddle

关于javascript - 从许多选定的表格行到一个 div 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37219180/

相关文章:

javascript - Accordion 面板不会打开(我如何让 div 落后于其他人)

javascript - 如何让这些添加的 div 从右边滑入?

html - 电子邮件 html - 如何更改我的 html/css 以使其在 Outlook 上看起来不错

jquery - 隐藏在div后面的下拉菜单

javascript - 如何阻止多个异步 Parse 云调用直到完成?

JavaScript 正则表达式使用一个字符两次

javascript - 将 YouTube 视频附加到 span

javascript - 非常基本的 HTML5 Canvas 代码无法运行。这是我还是我的浏览器?

javascript - d3 轴标记

javascript - 我在 jquery 上的循环代码不适用于循环内的 .each