1

編集:

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');

さらなる試み

// 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

私はこれを行うことになりました。jQueryUIを使用して選択可能なものをプログラムで選択する方法にありますか?

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

これにより、マウス停止イベントがトリガーされ、selectableでバインドされた停止機能が実行されます。よりエレガントな方法で停止をトリガーする方法があれば、私は見たいです。

于 2011-09-27T22:48:20.120 に答える