Tom*_*cik 1 html javascript forms jquery
所以我有一个非常简单的代码与表单和一个按钮与jQuery我想绑定一些操作当用户点击该按钮,但有些原因它不起作用
这是代码
<!DOCTYPE html>
<html>
<head>
<script src="jquery.js"></script>
</head>
<body>
<script>
$('#jallerysubmit').bind('click', function() {
alert('asd');
})
</script>
<form>
<input type="checkbox" name="box1">box1<br>
<input type="checkbox" name="box1">box2<br>
<input type="button" id="jallerysubmit" value="Proved">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
请说明这段代码有什么问题,因为它不起作用,即使它不会产生任何错误
您需要将其包装在document ready处理程序中.
<script>
$(function() {
$('#jallerysubmit').bind('click', function() {
alert('asd');
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
文档:http://api.jquery.com/ready/