1

编辑:

jQuery UI 可选小部件内置了一个回调stop,我需要知道如何以编程方式触发此事件。


(这措辞不好) 我已将事件侦听器附加到 jQuery UI Selectable Widget。如何以编程方式触发stop事件?


防爆可选:

$("table").selectable({
  filter: "tr",
  stop: function(){
    //do stuff
  }
});

// Various attempts at triggering the stop event
// one
$("table .ui-selected").click();

// two
$("table .ui-selected").select();

// three
$("table .ui-selected").trigger("click");

// shot in the dark 1
$("table").selectable('widget').trigger('stop');

// Shot in the dark 2
$("table").trigger('stop');

// really long shot in the dark
$("table").selectable('widget').call('stop');

进一步的尝试

// selectablestop event

$("#table").selectable('widget').trigger('selectablestop');

$("#table .ui-selected").trigger('selectablestop');
4

2 回答 2

12

如果您想在控件之外触发事件,您可以简单地调用.trigger(). 这假设您使用的是选项.bind()而不是匿名stop:function()选项。

$("#selectable").selectable({});
$("#selectable").bind("selectablestop", function(event) {
    $("body").append("<h1>did selectablestop</h1>");
});
$(":button").click(function() {
    $('#selectable').trigger('selectablestop');
});

jsfiddle上的代码示例。

编辑

另一种方法是检索stop:选项值(这将是函数)

var s = $('#selectable').selectable( "option" , "stop"); 
s(); //call the function.

jsfiddle上的代码示例。

于 2011-04-04T16:52:03.907 回答
4

我最终这样做了,在How to programmatically select selectables with jQuery UI?

 $('#selectable').data("selectable")._mouseStop(null);

这将触发鼠标停止事件并在可选对象上执行绑定的停止功能。如果有办法以更优雅的方式触发停止,我很乐意看到。

于 2011-09-27T22:48:20.120 回答