0

clickイベントが「クリックされた」場合、イベントがmouseover「オーバー」した場合など、イベントタイプに条件を設定できますか。しかし、私の関数は、関数がページにロードされているときに値を警告しています

<head>
<script type="text/javascript" src="jquery-1.7.2.js"></script>

<script type="text/javascript">
$(function() {

    if($('.wait').click()) {
        alert('click')
    }
    else if ($('.wait').mouseenter()) {
        alert('mouseenter')
    }
})
</script>

<style>
    .wait {color:#F00}
    .nowait {color:#00F}
</head>

<body>
    <div class="wait">abc.....</div>
    <div class="wait">abc.....</div>
    <div class="wait">abc.....</div>

</body>
4

6 に答える 6

3

構文が間違っています。代わりに次を使用してください。

$(".wait")
.click(function(event) {
    alert("click");
    // do want you want with event (or without)
})
.mouseenter(function(event) {
    alert("mouseenter");
    // do want you want with event (or without)
});
于 2012-10-01T15:20:27.973 に答える
3

この場合のアイデアは、さまざまなイベント タイプにさまざまなハンドラを定義することです。

   $('.wait').click(function(){
        alert('click')
    });
   $('.wait').mouseenter(function(){
        alert('mouseenter')
    });
于 2012-10-01T15:19:29.147 に答える
2

これを試して

(document).ready(function() {
   $('.wait').bind('click dblclick mousedown mouseenter mouseleave',
               function(e){
               alert('Current Event is: ' + e.type);
                    });
                   });
于 2012-10-01T15:23:29.067 に答える
0

複数のイベントハンドラーを同じオブジェクトにバインドする場合は、次のように、イベントマップ(オブジェクト)を.on()関数に個人的に渡します。

$('.wait').on({
    click: function(e) {
        alert('click');
        // handle click
    },
    mouseover: function(e) {
        alert('mouseover');
        // handle mouseover
    }
});

ただし、イベントタイプを出力するだけの場合は、次の簡単な方法があります。

$('.wait').on('click mouseover', function(e) {
    alert(e.type);
});
于 2012-10-01T15:28:25.200 に答える
0

簡単に試す

   $('.wait').click(function(){
        alert('click')
    });

   $('.wait').mouseenter(function(){
        alert('mouseenter')
    }); 
于 2012-10-01T15:20:36.097 に答える
0

それらを処理するために個別のイベントを作成します。

$('.wait').on('click',function(){
        alert('Click Event !!');
    });

   $('.wait').on('mouseenter'f,unction(){
        alert('MouseEnter Event !!')
    });
于 2012-10-01T15:21:07.483 に答える