javascript之dom编程(六):常用对象5
javascript之dom编程(6):常用对象5
一:form对象,验证两次输入是否一致
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<script type="text/javascript">
function check(){
var form1=document.forms.item(0);
var passwd=form1.passwd.value;
var passwd2=form1.passwd2.value;
if(passwd!=passwd2){
error2.innerText="两次输入密码不一致";
error2.style.display="inline";
return false;
}
}
</script>
<body>
<h1>用户注册</h1>
<form action="js-12.html" method="post">
<table border="0">
<tr><td>密 码:</td><td><input class="style1" type="password" name="passwd"
id="passwd"/></td></tr>
<tr><td>确认密码</td><td><input class="style1" type="password" name="passwd2"
id="passwd2"/><span style="display: none;color: red;" id="error2"></span></td></tr>
<tr><td><input type="submit" onclick="return check();" value="注册用户"></td><td><input
type="reset" value="重新填写"/></td></tr>
</table>
</form>
</body>
</html>
二;设置鼠标光标
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<script type="text/javascript">
function setFocus(){
document.getElementById("text1").focus();
}
</script>
<body>
<form>
name:<input type="text" id="text1" />
<br />
<input type="button" onclick="setFocus()" value="Set focus" />
</form>
</body>
</html>
一:form对象,验证两次输入是否一致
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<script type="text/javascript">
function check(){
var form1=document.forms.item(0);
var passwd=form1.passwd.value;
var passwd2=form1.passwd2.value;
if(passwd!=passwd2){
error2.innerText="两次输入密码不一致";
error2.style.display="inline";
return false;
}
}
</script>
<body>
<h1>用户注册</h1>
<form action="js-12.html" method="post">
<table border="0">
<tr><td>密 码:</td><td><input class="style1" type="password" name="passwd"
id="passwd"/></td></tr>
<tr><td>确认密码</td><td><input class="style1" type="password" name="passwd2"
id="passwd2"/><span style="display: none;color: red;" id="error2"></span></td></tr>
<tr><td><input type="submit" onclick="return check();" value="注册用户"></td><td><input
type="reset" value="重新填写"/></td></tr>
</table>
</form>
</body>
</html>
二;设置鼠标光标
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<script type="text/javascript">
function setFocus(){
document.getElementById("text1").focus();
}
</script>
<body>
<form>
name:<input type="text" id="text1" />
<br />
<input type="button" onclick="setFocus()" value="Set focus" />
</form>
</body>
</html>
版权声明:博主原创文章,转载请说明出处。http://blog.****.net/dzy21