zoukankan      html  css  js  c++  java
  • js表单的获取方法

    js中获取表单对象的方法   <input   type=”text” /> 

     HTML部分

      <form action="" name="form1" id="frm1" method="post">
    
                <input type="text" value="请输入用户名" name="number" id="number" ><br />
    
                <input type="button" value="提交"  onclick="checkForm()">
    
        </form>

    JS部分

    方法1:

    <script>
    
            funciton checkForm(){
    
            var obj=document.getElementById("number");
    
            alert(obj.value)
    
           }
    
    </script>

    方法2:

      <form id ="form1" action="test.do" method="post">
        <input type="text" name="a" value="1">
        <br>
        <input type="text" name="a" value="2">
        <br>
        <input type="text" name="a" value="3">
        <br>
        <input  type="submit" value="提交">
       </form> 
    
     </body>
      <script type="text/javascript">
             document.getElementById('form1').onsubmit=function(){
             var as=document.getElementsByName('a');  //数组
           for(i=0;i<as.length;i++){
            alert(as[i].value);
            }
         }
        </script>

    方法3:

    <script>
    
            funciton checkForm(){
    
                 var obj=document.form1.number.value;
    
                 var obj=document.forms[0].number.value;
    
                 var obj=document.forms[0]['number'].value;
    
                 var obj=document.form1['number'].value;
    
           }
    
    </script>



  • 相关阅读:
    构建前端第8篇之---Webstom搭建ES6运行环境
    方法重写
    继承的成员变量的访问特定
    继承的理解
    总结与新的开始
    python 小案例demo07
    python 小案例demo06
    python 小案例demo05
    python 小案例demo05 升级版石头剪刀布
    python 小案例demo04
  • 原文地址:https://www.cnblogs.com/ZXH-null/p/12624267.html
Copyright © 2011-2022 走看看