標籤:javascript
一: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.csdn.net/dzy21
javascript之dom編程(6):常用對象5