javascript之dom編程(6):常用對象5

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.