• jquery获取表单元素


        表单验证需要获得表单元素,下面是获取表单元素的方法

        例子:

       

    View Code
    <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)

    等等....

    多思考,多创新,才是正道!
  • 相关阅读:
    【Python】ModuleNotFoundError: No module named 'matplotlib.pyplot'
    【DB2】DB2使用IMPORT命令导入含有自增长列的表报错处理
    ~~
    汉字的unicode码范围是多少?
    字符编码(ASCII,Unicode和UTF-8) 和 大小端(zz)
    是否 whether ,if
    定语从句:
    by,with
    C++中extern “C”含义深层探索
    安装Office2007时出现1706错误的解决方案
  • 原文地址:https://www.cnblogs.com/shuang121/p/2080876.html
Copyright © 2020-2023  润新知