首页javascriptformJavascript Form - 如何从表单对象的元素数组访问表单元素

Javascript Form - 如何从表单对象的元素数组访问表单元素

我们想知道如何从表单对象的元素数组访问表单元素。


<html>
    <body>
    <script language="JavaScript">
    function getName(){
         var textName = document.form1.elements[0].name;
         console.log("The textbox name is: " + textName);
    }
    </script>
    <form name="form1">
    This is a blank input textbox. Click on the button below to get the name of the textbox.
    <br>
    <input type="text" name="textbox1" size=25>
    <br><br>
    <input type="button" value="Get Name" onClick = getName()>
    </form>
    </body>
</html>