触发jQuery UI事件:ui-selectable

Der*_*air 1 jquery jquery-ui jquery-ui-selectable

编辑:

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


(这个措辞很差) 我已经将一个事件监听器附加到jQuery UI Selectable Widget.如何以编程方式触发stop事件?


Ex可选:

$("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');
Run Code Online (Sandbox Code Playgroud)

进一步尝试

// selectablestop event

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

$("#table .ui-selected").trigger('selectablestop');
Run Code Online (Sandbox Code Playgroud)

Mar*_*man 12

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

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

关于jsfiddle的代码示例.

编辑

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

var s = $('#selectable').selectable( "option" , "stop"); 
s(); //call the function.
Run Code Online (Sandbox Code Playgroud)

关于jsfiddle的代码示例.