1234567891011121314151617181920212223242526272829303132 |
- <html>
- <head>
- <title>form - test</title>
- </head>
- <body>
- <h1>Form</h1>
- <form id="myform">
- <input id="myinput" type="text" name="q" value="foo"/>
- <button type="submit">submit</button>
- </form>
- <div id="value"></div>
- <script>
- function getParameterByName(name) {
- var url = window.location.href;
- name = name.replace(/[\[\]]/g, "\\$&");
- var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
- results = regex.exec(url);
- if (!results) return null;
- if (!results[2]) return '';
- return decodeURIComponent(results[2].replace(/\+/g, " "));
- }
- var q = getParameterByName('q');
- if (q) {
- document.querySelector('#value').innerHTML = q;
- }
- </script>
- </body>
- </html>
|