jquery関数の使用と使用on
後の呼び出しの違いは何ですかfind
on
<div class="outer">
<span>One</span>
<div class="inner"><button id="button">button 1</button></div>
</div>
<div class="outer">
<span>Two</span>
<div class="inner"><button id="button">button 2</button></div>
</div>
jqueryコードは
$(document).ready(function(){
$('div.outer').on('click',".inner #button",function(event){
console.log(this);//this works
});
$('div.outer').find(".inner #button").on("click",function(event){
console.log(this);//this works
});
$('div.outer').find(".outer span").on('click',function(event){
console.log(this);//this not works
});
});
これは、各ボタンが 2 回クリックされるように、複数のインスタンスを持つ jquery プラグインを作成している簡単な例です。jquery.off
各関数をバインドする前に使用しましたが、機能しません。