-3
$(function () {
    $(".items").on('click', 'a', function () {
        //nothing gets executed here, alert wont come
        alert("doesn't work")
    }, function () {
        //this function gets executed
        alert("works")
    });
});

最初の関数が機能しないのはなぜ.on()ですか。このように機能するはずがないのですか? 私の代替手段は何ですか?

4

3 に答える 3

2

2 番目の関数はイベント ハンドラーになります。最初の関数はデータとして渡されます。

于 2013-07-02T18:01:05.873 に答える
1

on()のように複数のハンドラはありませんhover()。3 番目のパラメーターは、データをハンドラーに渡すためのものです。dataパラメータをハンドラーのコールバックとして使用したい場合、これはオプションになると思います。これにより、両方の関数が呼び出されます: http://jsfiddle.net/M4x4u/1/

$(function () {
    $(".items").on('click', 'a', function () {
        //nothing gets executed here, alert wont come
        alert("doesn't work")
    }, function (e) {
        //this function gets executed
        alert("works")
        e.data();
    });
});
于 2013-07-02T18:05:44.647 に答える
0

と混同onしているようですtoggle

$(function() { 
  $(".items").on('click',  'a', function() { 
    alert("this works now")
  });
});
于 2013-07-02T18:03:32.260 に答える