javascript中document.form[formName][]的意思


近来重新学习javascript发现还有很多知识点模糊,今天就javascript中的document.forms[formName][inputName]进行说明:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>javascript中的form</title>
    </head>
    <body>
        <form name="myForm">
          <input type="text" name="myInput" value="">
          <input type="submit" value="提交">
        </form>
    </body>
</html>        

  

var sub=document.getElementByTagName("input")[1];
sub.onclick=function(){
  var x=document.forms["myForm"]["myInput"].value;
console.log(document.forms["myForm"]["myInput"]);
if(x==""||x==null){
alert("请填入姓名");
return false; }
}

  说明:document.forms[formName];//如果文档中有多个form,取出的是哪一个form;

              document.forms[formName][inputName]//如果该form中有多个input,取出的               是哪一个input;

      注意:平常都是用document.getElementsByTagName("")[]找到该元素。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM