来源:http://sm0210.cn/post/500.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JQuery阻止默认行为</title>
<script language="javascript" src="JS/jquery-1.3.1.js"></script>
<script language="javascript">
$(function(){
$("#sub").bind("click",function(event){
var name=$("#username").val();
if(name==""){
$("#msg").html("<p>文本框的值不能为空</p>");
event.preventDefault(); //阻止行为
}
});
});
</script>
</head>
<body>
<form id="form1" name="form1" action="">
用户名:<input type="text" id="username"/><br/><br/>
<input type="submit" value="提交" id="sub"/>
</form>
<div id="msg"></div>
</body>
</html>
来源:http://sm0210.cn/post/500.html
-------------------------------------------------------------------------------------------------------------------
评论