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>
jQuery代碼
<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不顯示任何警報框? 有什麼建議嗎?
您可能正在使用Internet Explorer,並且由於traili語法錯誤ng','在你的物體中。 – 2013-05-02 11:18:28
如果它是動態創建的元素,您可能想要使用.on委託,就像您用於#ohno按鈕 – 2013-05-02 11:18:39
@ÁlvaroG.Vicario - 敏銳的目光。 '+ 1' – ahren 2013-05-02 11:18:50