要获取文档中第一个表单的名称,请在表单属性中使用。您可以尝试运行以下代码以显示名称-
<!DOCTYPE html> <html> <body> <form name ="formOne"> Name: <input type="text" name="my_name" value="Amit"> Subject: <input type="text" name="my_subject" value="Java"> <input type="submit" value="Submit"> </form> <form name ="formTwo"> </form> <script> var val = document.forms.length; document.write("<br>Number of forms in the document: "+val); document.write("<br>Name of the first form: "+document.forms[0].name) </script> </body> </html>