2016-05-13 36 views
0

使用jQuery中的可選小部件,我做了一個函數來選擇表中的行。現在我想要選定的行將形成一個div標籤(不是很多,只是一個大的div),並要div標籤能夠添加像draggable和resizable等其他功能,如何做到這一點?從許多選定的錶行到一個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; } 

回答

1

你可以只克隆出來,把一些容器是這樣的:

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

但他們不會像表中的行,你需要準備不同的風格他們如果你想要的。

JSFiddle

+0

是個好主意,但之後當頁面需要重新加載不會有選擇的區域克隆,我開了另外一個問題更精確地在這裏看到:[FIX-高度的安 - 絕對定位-DIV標籤功能於一個列表(http://stackoverflow.com/questions/37221523/fix-height-of-an-absolute-positioned-div-tag-in-a-list) 。 –