jQuery按钮选择器,点击事件不起作用

时间:2013-10-15 18:13:17

标签: jquery

为什么这不起作用?

<div id="download">
        <button>Download</button>
</div>

$("#download").find( ":button" ).click(function () {
    alert("io");
});

我尝试在按钮元素中添加一个类和一个Id。我也试过

<button>Download</button>

$(':button').click(function(){
    alert("io");
}

1 个答案:

答案 0 :(得分:2)

:button仅匹配<input type="button"...

所以试试:

$(function(){ //And i would wrap it in DOM ready wrapper if the script is loaded earlier than the element in DOM.
    $("#download").find("button").click(function () {
        alert("io");
    });
});