
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
String.prototype.trim = function() { return this.replace(/(^\s+)|(\s+$)/g, ''); }
function check(obj){
if(obj.value.length <=0 ||obj.value.trim()=="") {
document.getElementById("errorinfo").style.display = "block";
document.getElementById("submit").disabled = true;
} else {
document.getElementById("errorinfo").style.display = "none";
document.getElementById("submit").disabled = false;
}
}
</script>
</head>
<body>
<!--
<p style="color:#FF0000" align="center">温馨提示:带"*"为必填内容</p>
-->
<form name="form1" method="post" action="www.baidu.com" >
<table>
<tr>
<td >账号:</td>
<td ><input name="username" type="text" id="username" onblur="check(this)"/>
* <div style="display:none" id="errorinfo"><font color="red">账号不能为空</font></div></td>
</tr>
<tr>
<td >
<input type="submit" value="提交" id="submit" style="width:50px" disabled="disabled"/>
</td>
</tr>
</table>
</form>
</body>
本文介绍了一个简单的HTML页面,该页面使用JavaScript实现表单验证功能,确保用户输入的账号不为空。通过`onblur`事件触发验证,若输入为空则显示错误提示并禁用提交按钮。
862

被折叠的 条评论
为什么被折叠?



