JavaScript 基礎,登入驗證

來源:互聯網
上載者:User

標籤:div   fun   width   radio   font   元素   idt   value   set   

1、<script></script>的三種用法:

a放在<body>中


<body>
<p id="meto">標準北京時間</p>
<script >
document.getElementById(‘meto‘).innerHTML = Date()
</script>
<script type="text/javascript">alert("廣州商學院") </script>

</body>
 

b放在<head>中

<head>    <meta charset="UTF-8">    <title> 歡迎來到登入介面,請登入 </title>    <script type="text/javascript">alert("廣州商學院")  </script><script type="text/javascript"src="../static/jsp/ma.js"></script></head>

c放在JS檔案中

 

 

 

 

 

 

 

 

 

三種輸出資料的方式:

  1. 使用 document.write() 方法將內容寫到 HTML 文檔中。
    <body><script>document.write(Date())</script></body>

     

  2. 使用 window.alert() 彈出警告框。
    <body><button type="button" onclick=window.alert("請等候.......")>登入</button></body>

     

  3. 使用 innerHTML 寫入到 HTML 元素。
<body><p id="meto">中國標準時間</p><script>document.getElementById("meto").innerHTML=Date()</script></body>

 

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>歡迎來到登入介面,請登入</title>    <script type="text/javascript" src="static/js/ma.js"></script></head><body><p id="meto">中國標準時間</p><script>document.getElementById("meto").innerHTML = Date()</script><div id="container" style="width: 300px">    <div id="header" style="background-color: darkorange"><h2 align="center">登陸介面</h2></div>    <div id="content">            <p align="center">使用者名稱:<input id="uname" type="text" name="user" placeholder="請輸入帳號">            </p>            <p align="center"> 密碼&nbsp:<input id="upass" type="password" name="psw" placeholder="請輸入密碼"></p>            <br>            <div id="error_box"><br>            </div>            <input type="radio" value="stu">學生            <input type="radio" value="tea">老師            <br>            <input type="checkbox" value="true">記住密碼 <a href="">登陸遇到問題</a><br>            <button onclick="fnLogin()">登陸</button>            &nbsp&nbsp&nbsp            <input type="button" name="regist" value="註冊">    </div>    <div id="footer" style="background-color: darkgoldenrod"><h3 align="center">著作權@</h3></div>
function fnLogin() {    var oUname = document.getElementById("uname")    var oUpass = document.getElementById("upass")    var oError = document.getElementById("error_box")    if (oUname.value.length > 20 || oUname.value.length < 6) {        oError.innerHTML = "請輸入使用者名稱6-20位字元"    }    if (oUpass.value.length > 20 || oUpass.value.length < 6) {        oError.innerHTML = "請輸入密碼 6-20位字元"    }}

 

JavaScript 基礎,登入驗證

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.