jQuery3で、グループ化してイベントを外します。
【手順】
1.『jQuery3.1.0のダウンロード方法』の手順で、jQuery3.1.0をダウンロードしておきます。
2.『index.html』というファイルを作成。
3.『index.html』を以下の様に入力。
<!doctype html>
<html>
<head>
<script src="jquery-3.1.0.min.js"></script>
<script>
$(function() {
var countA = 0;
var countB = 0;
$(document).on("click.countGroup", "#button", function(){
++countA;
});
$(document).on("click.countGroup", "#button", function(){
++countB;
});
$(document).on("click", "#button", function(){
$("#spn").html("countA=" + countA + ", countB=" + countB);
});
$("#off-button").click(function(){
$(document).off("click.countGroup");
});
});
</script>
</head>
<body>
<button id="off-button">off</button>
<button id="button">呼び出し</button>
<span id="spn" />
</body>
</html>
4.ダウンロードした『jquery-3.1.0.min.js』と『index.html』を同一ディレクトリに配置します。
5.『index.html』をブラウザで開きます。
6.以下の様に表示されれば成功です。
以上です。

0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。