请问怎么在JavaScript中访问HTML标签中的对象,比如:
<html>
  <head>
    <script>
       function check(){
           
        }
    </script>
  </head>
  <body>
    <html:form action="form.do" name="mf" id="mf">
      <html:text property="name"></html:text>
    </html:form>
  </body>
</html>
请问怎么在JavaScript中验证<html:text property="name"></html:text>是否为空,好像用id,和name都不可以表示这个对象,应该怎样呢?

解决方案 »

  1.   

    在JavaScript定义一个function,然后在function里用document.mf(也就是你的表单form的name).name(这个是你表单中的标签的name).value();
    具体的例子我引用你给的给你说一下吧: <html:form action="form.do" name="mf" id="mf"> 
          <html:text property="name"> </html:text> 
        </html:form> 
    在JavaScript中写
    function check(){
       var name = document.mf.name.value();
       if(name==null){
        写你想处理的代码就可以了
       }
    }
      

  2.   

    修改下,你在document.mf.name.value;在value中没有括号,然后你在表单中用onClick()触发这个function就可以了
      

  3.   

    function check(){
        if(document.getElementById("text").value==""){
                处理代码
        }else{
             return true;
        }
    }
     <body> 
        <html:form action="form.do" name="mf" id="mf"> 
          <html:text property="name" id="text"> </html:text> 
        </html:form> 
      </body>
      

  4.   


    <html>
      <head>
      
        <script>
          function check(){
             var value =document.getElementById("name").value;
             if(value == "")
              alert("name的值为空");
             else 
                alert("name的值为    "+ value)
            }
        </script>
      </head>
      <body>
        <form action="form.do" name="mf" id="mf">
          name :<input type="text" property="name" id ="name"><br>
          <input type="button" value="测试是不是为空" onclick="check()">
        </form>
      </body>
    </html> 我给你实现了下,你看看吧。
      

  5.   

    document.getElementById(id)
    document.getElementsByName(name)
      

  6.   

    document.getElementById(id) 
    document.getElementsByName(name)
    document.getElementsByTagName(name)