通过name获取元素,该元素必须是在<form>表单里,而且必须是表单元素
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>无标题文档</title>
- </head>
-
- <body>
- <form name="form1">
- <input type="text" name="input_text" value="dddd"/>
- </form>
- </body>
- </html>
- <script type="text/javascript">
- window.onload = function(){
- var input_obj = document.form1.input_text;
- alert(input_obj.value)
- }
- </script>