<html>
<head>
<script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("#sub").bind("click",function(event){
var username = $("#username").val(); //獲取元素的值
if(username==""){ //判斷值是否為空
$("#msg").html("<p>文本框的值不能為空.</p>"); //提示信息
event.preventDefault(); //阻止默認(rèn)行為 ( 表單提交 )或者return false;
}
})
})
</script>
</head>
<body>
<form action="test.html">
用戶名:<input type="text" id="username" />
<br/>
<input type="submit" value="提交" id="sub"/>
</form>
<div id="msg"></div>
</body>
</html>