簡單的jQuery代碼

來源:互聯網
上載者:User

標籤:utf-8   document   使用者名稱   title   omd   charset   cli   har   htm   

簡單的jQuery代碼

使用者名稱: 密 碼:

<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title>簡單的jQuery代碼</title>    <!--引入jQuery指令碼-->    <script src="scripts/jquery-3.1.1.js" type="text/javascript "></script>    <script type="text/javascript">        /*可以寫JS jQuery代碼*/        //window.onload=function(){alert("今天風好大");};//JS寫法        //等價的jQuery寫法        //1.        /* jQuery(document).ready(function(){         alert("今天風好大");         });         //2.         $(document).ready(function(){         alert("今天風好大");         });*/        //3.        $(function(){            alert("風真的好大啊");            document.getElementById("id1").onclick=function(){                //擷取使用者名稱  密碼裡面的value                //js寫法                var name = document.getElementById("name");                var password = document.getElementById("password");                alert("name:"+name.value+"\n"+"password"+password.value);                //jQuery寫法 等價於JS寫法                alert("name:"+$("#name").val());                alert("password:"+$("#password").val());                //$("#name"):擷取的是jQuery對象                //document.getElementById("name"):DOM中的對象                var $name =$("#name");                var name = $name[0];                alert(name.value);                //DOMduixiang =>jQuery對象                var password = document.getElementById("password");                //可以理解為$()就是jQuery對象的建構函式                var $password = $(password);                alert($password.val);            }        });    </script></head><body>使用者名稱:<input id="name" type="text">密 碼:<input id="password" type="password"><input id="id1" type="button" value="提交"></body></html>

  

簡單的jQuery代碼

聯繫我們

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