如何使用jQuery UI sortable绑定停止事件?
当我尝试使用可排序事件时。(例如如何使用jQuery UI sortable绑定停止事件?,jquery,jquery-ui-sortable,Jquery,Jquery Ui Sortable,当我尝试使用可排序事件时。(例如stop()事件)仅当我使用以下方法绑定它时,它才起作用: $('.selector').bind('sortstop', function(event, ui) { ... }); 而不是 $('.selector').sortable({ stop: function(event, ui) { ... } }); 这里面少了一块吗 我问这个问题的唯一原因是,当我使用实际的bind()方法进行绑定时,它不允许我访问传入的事件或ui参数。我总是返回未
stop()
事件)仅当我使用以下方法绑定它时,它才起作用:
$('.selector').bind('sortstop', function(event, ui) {
...
});
而不是
$('.selector').sortable({
stop: function(event, ui) { ... }
});
这里面少了一块吗
我问这个问题的唯一原因是,当我使用实际的bind()方法进行绑定时,它不允许我访问传入的事件或ui参数。我总是返回未定义的值。Hrm,如果函数的参数是未定义的值,那听起来像是一个bug。为了回答您的特定问题,您的第二行(
$('.selector').sortable({stop:function(event,ui){…}});
)在第一行初始化调用sortable()
后将无效。要在初始化调用后更改选项,请调用选项
方法:
$('.selector').sortable('option', 'stop', function(event, ui) { /* ... */ });
Hrm,如果函数的参数是未定义的值,那么这听起来像是一个bug。为了回答您的特定问题,您的第二行(
$('.selector').sortable({stop:function(event,ui){…}});
)在第一行初始化调用sortable()
后将无效。要在初始化调用后更改选项,请调用选项
方法:
$('.selector').sortable('option', 'stop', function(event, ui) { /* ... */ });
sortable的示例用法
$('.selector').sortable({
change: function(event, ui) {
ui.placeholder.parent().children().show();
ui.placeholder.parents("li:first").find(".sortaccordion:first").attr('src',prefix+'/img/accordionopen.gif');
},
stop: function(event, ui) {
// do stuff here
}
});
如果这不起作用,那么可能您有一些其他问题,比如您没有加载ui排序表,或者您的html不好
您有任何错误吗?使用sortable的示例
$('.selector').sortable({
change: function(event, ui) {
ui.placeholder.parent().children().show();
ui.placeholder.parents("li:first").find(".sortaccordion:first").attr('src',prefix+'/img/accordionopen.gif');
},
stop: function(event, ui) {
// do stuff here
}
});
如果这不起作用,那么可能您有一些其他问题,比如您没有加载ui排序表,或者您的html不好
您有任何错误吗?@colorandcode您能让它工作吗?@colorandcode您能让它工作吗?