查找表单中每个元素的值
- <!DOCTYPE html>
- <html>
- <body>
-
- <form id="frm1" action="/demo/demo_form.asp">
- 名:<input type="text" name="fname" value="Bill"><br>
- 姓:<input type="text" name="lname" value="Gates"><br><br>
- <input type="submit" value="提交">
- </form>
-
- <p>单击“试一试”以显示表单中每个元素的值。</p>
-
- <button onclick="myFunction()">试一试</button>
-
- <p id="demo"></p>
-
- <script>
- function myFunction() {
- var x = document.getElementById("frm1");
- var text = "";
- var i;
- for (i = 0; i < x.length ;i++) {
- text += x.elements[i].value + "<br>";
- }
- document.getElementById("demo").innerHTML = text;
- }
- </script>
-
- </body>
- </html>