JS 獲取和設定input值,控制表單提交地址 阿新 • • 發佈:2019-02-15 以 JS 注入的方式獲取和設定input域的值: <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script type="text/javascript" src="jquery.js"></script> </head> <body> 獲取和設定input的值:<input type='text' id='provSelect1' name='provSelect1' /> <script> // 方式一: 直接通過 JS 獲取/設定input域的值 window.onload = function(){ var psel = document.getElementById("provSelect1"); alert("獲取到的value:" + psel.value+" ,"+$("#provSelect1").val()); //獲取 psel.value = "123"; //設定 alert("設定後的value:" + psel.value); //設定後的 }; // 方式二: 通過 JQuery 獲取/設定input域的值 $(document).ready(function(){ var val = $("#provSelect1").val(); //獲取 alert("獲取到的value:" + val); $("#provSelect1").val("123"); //設定 alert("設定後的value:" + $("#provSelect1").val()); }); </script > </body> </html> js控制一個表單提交不同地址 <html> <scripttype="text/javascript"> function update(){ form.action="update.html"; form.submit(); } function refresh(){ form.action="ajaxmysql.html"; form.submit(); } </script><body> <form name="form"method="post"> <inputtype="text" name="t1"> <inputtype="button" value="update"onclick="update()"> <inputtype="button" value="refresh"onclick="refresh()"> </form></body></html>