問題描述
jQuery 的 draggable
功能似乎不適用于表格(在 FF3 或 Safari 中).很難想象這會如何工作,所以它不工作也就不足為奇了.
jQuery's draggable
functionality doesn't seem to work on tables (in FF3 or Safari). It's kind of difficult to envision how this would work, so it's not really surprising that it doesn't.
<html>
<style type='text/css'>
div.table { display: table; }
div.row { display: table-row; }
div.cell { display: table-cell; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://dev.jquery.com/view/tags/ui/latest/ui/ui.core.js"></script>
<script src="http://dev.jquery.com/view/tags/ui/latest/ui/ui.draggable.js"></script>
<script>
$(document).ready(function(){
$(".row").draggable();
});
</script>
<body>
<div class='table'>
<div class='row'>
<div class='cell'>Foo</div>
<div class='cell'>Bar</div>
</div>
<div class='row'>
<div class='cell'>Spam</div>
<div class='cell'>Eggs</div>
</div>
</div>
<table>
<tr class'row'><td>Foo</td><td>Bar</td></tr>
<tr class='row'><td>Spam</td><td>Eggs</td></tr>
</table>
</body>
</html>
我想知道 a) 是否有任何特定原因導致這不起作用(從 w3c/HTML 規范的角度來看)以及 b) 獲取可拖動表格行的正確方法是什么.
I'm was wondering a) if there's any specific reason why this doesn't work (from a w3c/HTML spec perspective) and b) what the right way to go about getting draggable table rows is.
我喜歡真正的表格,因為它有邊框折疊和行高算法——任何可以做這些事情的替代方案都可以正常工作.
I like real tables because of the border collapsing and row height algorithm -- any alternative that can do those things would work fine.
推薦答案
如果你有真正的表格數據,你確實應該堅持使用表格.
If you have truly tabular data, you should stick with table indeed.
如果你想在表格中拖動行,這個JQuery + "可拖動行表" 庫 在 FireFox3 中完美運行
And if you want to drag rows within a table, this JQuery + "draggable row table" library works perfectly in FireFox3
這篇關于jQuery可拖動表格元素的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!