$('div.something').sortable(options)
工作正常,但在$('div.something').unbind();
之后中断。尝试在$('div.something').sortable(options);
之后重新运行$('div.something').sortable('refresh');
或$('div.something').unbind();
无效。
我正在使用$ .unbind通过从应用插件的元素中删除事件来停用/取消启动插件,但是这种技术会产生不利影响,因为它打破了$ .sortable。 关于如何重新激活可排序的任何想法?
我正在使用最新版本的jQuery和jQuery UI。
答案 0 :(得分:9)
在调用.sortable('destroy')
之前拨打.unbind()
将完全删除元素中的可排序功能。
这确保在执行对.unbind()
的某种危险调用之前进行适当的拆除,这将删除元素上的所有绑定处理程序。然后,您可以重新初始化可排序功能。
// Initialization of the sortable feature
$('div.something').sortable(options);
...
// Remove the sortable feature to prevent bad state caused by unbinding all
$('div.something').sortable('destroy');
// Unbind all event handlers!
$('div.something').unbind();
...
// Re-initialize the sortable feature
$('div.something').sortable(options);
答案 1 :(得分:7)