运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Document Object</h1> <h2>The forms Property</h2> <p><form id="myCarForm"> Favorite Car: <input type="text" name="fname" value="Volvo"> </form></p> <p><form id="myColorForm"> Favorite Color: <input type="text" name="favcolor" value="Blue"> </form></p> <p>The name of the form elements in the document are:</p> <p id="demo"></p> <script> const forms = document.forms; let text = ""; for (let i = 0; i < forms.length; i++) { text += forms[i].id + "<br>"; } document.getElementById("demo").innerHTML = text; </script> </body> </html>