Reprint address: http://aquarius-zf.iteye.com/blog/605144
The most common page element in the page is the input, but how do we use JavaScript to get the value entered in the input of the web page? It is actually very simple, and there are more than one method. According to my summary, the most commonly used are the following two methods. , I won't say much more gossip, let's take a look at the method I said:
Method 1,
- <html>
- <head>
- <script language="javascript">
- function print(){
- var a=myform.name.value;
- alert(a);
- }
- </script>
- </head>
- <body>
- <form name="myform">
- <input type="text" name="name" id="nn" />
- <input type="button" name="button" value="获取" onclick="print()" />
- </form>
- </body>
- </html>
Method Two,
- <html>
- <head>
- <script language="javascript">
- function print(){
- var a=document.getElementById("nn").value;
- alert(a);
- }
- </script>
- </head>
- <body>
- <form>
- <input type="text" name="name" id="nn" />
- <input type="button" name="button" value="获取" onclick="print()" />
- </form>
- </body>
- </html>