我有以下代码:
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>StarTrackr!</title>
<script src="../../lib/jquery-1.7.1.min.js" type="text/javascript"
charset="utf-8"></script>
<script type="text/javascript">
$(document).ready(function () {
$('div').load('1.htm');
// The above function does work
$("#testform").submit(function () {
//Code after form submitted and this does not fire
alert("hi");
});
});
</script>
</head>
<body>
<div></div>
<form id="testform">Email:
<input type="text" name="email" />
<br />First Name:
<input type="text" name="fname" />
<br />Last Name:
<input type="text" name="lname" />
<br />
<input type="button" name="submit" id="submit" value="Submit" />
</form>
</body>
</html>
当我点击提交按钮时,警告(hi)应弹出,但不会。有谁知道为什么?假设正确加载了Jquery库
谢谢, 吉姆
答案 0 :(得分:4)
input
需要type="submit"
,而不是type="button"
。
答案 1 :(得分:0)
<input type="button" name="submit" id="submit" value="Submit" />
将type =“button”更改为type =“submit”