0

jquery mobileでは、ドキュメントよりも低い要素にバインドされると、swipeleftイベントが2回トリガーされるため、プラグインによって選択されたすべてのオブジェクトにswipeleftイベントをバインドする必要があります。次のプラグインは次のように初期化されます。

$('#mylistview li').myPlugin();

$.fn.myPlugin = function(o){    

    return this.each(function(i, el){
        this.on("swipeleft", function ( e ) {
            ...
}

このコードは、swipeleftイベントを各要素にバインドしていますが、ドキュメントレベルで実行する必要があります。これをjqueryセレクターとして使用するにはどうすればよいですか?上記のコードはエラーになります

   $.fn.myPlugin = function(o){ 
       return this.each(function(i, el){
                      //how to use "this" as a selector???
           $(document).on('swipeleft', this,  function(event){
            ...
    }
4

1 に答える 1

0

関数を次のように書き直すことができます。

$.fn.myPlugin = function(o) {
   var selector = this.selector;
   return this.each(function(i, el) {
      $(document).on('swipeleft', selector,  function(event) {
         // Code goes here
      });
   });
}
于 2013-01-17T08:35:29.363 に答える