用jquery擷取表單元素

來源:互聯網
上載者:User

標籤:

 表單驗證需要獲得表單元素,下面是擷取表單元素的方法

 例子:

<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title>無標題頁</title>    <script src="js/jquery-1.6.min.js" type="text/javascript"></script>    <script type="text/javascript">       jQuery(function($){         $("#btnCheck").click(function(){          $("#msn").html(           "input元素有:"+$(":input").length+"個(取得所有表單元素)<br/>"+           "text元素有:"+$(":text").length+"個(取得所有表單元素)<br/>"+           "password元素有:"+$(":password").length+"個(取得所有表單元素)<br/>"+           "radio元素有:"+$(":radio").length+"個(取得所有表單元素)<br/>"+           "checkbox元素有:"+$(":checkbox").length+"個(取得所有表單元素)<br/>"+           "button元素有:"+$(":button").length+"個(取得所有表單元素)<br/>"           );         })       })    </script></head><body>    <form id="form1" runat="server">    <label>使用者名稱:</label><input type="text" id="userName" /><br />    <label>密  碼:</label><input type="password" id="userPwd" /><br />    <label>性  別:</label><input type="radio"  name="sex" />男    <input type="radio"  name="sex" />女<br />    <label>愛好:</label><input type="checkbox"  name="chk" />上網    <input type="checkbox"  name="chk" />唱歌<br />    <input id="btnCheck" type="button" value="button" />    <span id="msn"></span>    </form></body></html>

  

:input:所有表單元素

:text:獲得所有text元素的元素,如要獲得所有值,必須有each迴圈獲得

:password:獲得屬性為password的元素

:checkbox:獲得所有checkbox元素的元素,如要獲得選中的值,則需要用each迴圈獲得(:checkbox:checked)

原帖:http://www.cnblogs.com/shuang121/archive/2011/06/14/2080876.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.