`
爪哇夜未眠
  • 浏览: 28429 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

超链接-限制文本框中输入的字数-提交与重置事件

 
阅读更多
<html>
<head>
<title>在超链接中使用事件</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script type="text/javascript" language="javascript">
<!--
//多添加几个换行,让效果明显
for (var i=0;i<100;i++)
{
document.write("<br>");
}
-->
</script>
</head>
<body>
<a onclick="alert('您单击了第二个超链接')">第1个超链接</a><br>
<a href="#" onclick="alert('您单击了第二个超链接')">第2个超链接</a><br>
<a href="javascript:alert('您单击了第三个超链接')">第3个超链接</a><br>
</body>
</html>



限制文本框中输入的字数

<html>
<head>
<title>限制文本框中输入的字数</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script type="text/javascript" language="javascript">
<!--
function checkDate(TextValue)
{
if (TextValue.length>6)
{
alert("邮编不能大于6位");
TextValue = TextValue.substr(0,6);
myForm.PostCode.value = TextValue;
}
}
-->
</script>
</head>
<body>
<form name="myForm">
邮编:<input type="text" onkeyup="checkDate(this.value)" name="PostCode">
</form>
</body>
</html>


提交事件与重置事件

<html>
<head>
<title>提交事件与重置事件</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script type="text/javascript" language="javascript">
<!--
//验检数据有效性
function checkDate()
{
if (myForm.myName.value=="")
{
alert("请输入姓名");
}
else if (myForm.myPassword1.value=="")
{
alert("请输入密码");
}
else if (myForm.myPassword2.value=="")
{
alert("请重复密码");
}
else if (myForm.myPassword1.value!=myForm.myPassword2.value)
{
alert("两次密码输入不一致,请重新输入");
}
else if (myForm.postalcode.value.length!=0 && myForm.postalcode.value.length!=6)
{
alert("邮编应该是6位的数字");
}
else
{
return true;
}
return false;

}
//提示清除表单
function resetForm()
{
return confirm("该操作将会清除表单中的所有数据。\n是否确定重置表单?");
}
-->
</script>
</head>
<body>
<form name="myForm" onsubmit="return checkDate()" onreset="return resetForm()" action="submit.htm">
姓名:<input name="myName" type="text">*<br>
密码:<input name="myPassword1" type="password">*<br>
重复密码:<input name="myPassword2" type="password">*<br>
地址:<input name="address" type="text"><br>
邮编:<input name="postalcode" type="text"><br>
<input type="submit" value="注册"> <input type="reset" value="重置">
</form>
</body>
</html>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics