0

HTMLコード

<body>
<h1 align="center">Are you ready?</h1>
<h2 align="center">Just answer Yes or No!</h2>
<div class="wrapper">
    <button id="ohyes" class="buttonYes"> Yes </button>
    <button id="ohno" class="buttonNo"> No </button>
</div>
</body>

Jクエリコード

<script>
$(function () {
    $("#ohno").on({
        mouseover: function () {
            $(this).css({
                left: (Math.random() * 800) + "px",
                right: (Math.random() * 800) + "px",
                top: (Math.random() * 400) + "px",
            });
        }

    });

    $("#ohyes").click(function () {
        alert("yes"); //use .val() if you're getting the value
    });
});
</script>

最初にjqueryで関数を呼び出そうとしていますが、マウスオーバーでボタンが動いていますが、IDがohyesのボタンをクリックしてもアラートボックスが表示されませんか? 助言がありますか?

4

2 に答える 2

0

これを試してください:これはohyes、クリックイベントの2番目のボタンで警告します。

$(document).ready(function(){
    $("#ohno").mouseover(function(){
        $(this).css({
            left:(Math.random()*800)+"px",
            right:(Math.random()*800)+"px",
            top:(Math.random()*400)+"px",
        });
    });

    $("#ohyes").click(function(){ 
         alert("yes");  //use .val() if you're getting the value
    });  
});
于 2013-05-02T11:24:08.940 に答える