网络编程 
首页 > 网络编程 > 浏览文章

用JS动态改变表单form里的action值属性的两种方法

(编辑:jimmy 日期: 2025/10/23 浏览:3 次 )

方法1:

<form id="form1" name="form1" method="post" action="../news/index.asp">
   <table width="100%" height="43" border="0" cellpadding="0" cellspacing="0">
    <tr>
     <td height="28"><input name="keyword" type="text" style="width:150px" id="keyword"/></td>
    </tr>
    <tr>
     <td height="28"><select name="Searchtype" style="width:110px" id="Searchtype" onchange="Searchtype1();">
      <option value="news" selected="selected">新闻中心</option>
      <option value="case">工程案例</option>
     </select>
     <input type="submit" name="Submit" value="搜索" /></td>
    </tr>
   </table>
 </form>
 <script language="javascript">
 function Searchtype1(){
 var type=document.getElementById("Searchtype").options[document.getElementById("Searchtype").selectedIndex].value;
 if (type=="news"){document.getElementById("form1").action="../news/index.asp"}
 else if (type=="case"){document.getElementById("form1").action="../case/index.asp"}
 }
 </script>

方法2:

<html>
<head>
<script language="javascript">
function check(){
if(document.form1.a[0].checked==true)
document.form1.action="1.htm"
else
document.form1.action="2.htm"
}
</script>
</head>
<body>
<form name="form1" method="post" action="" onSubmit="check();">
转到页面一<input type="radio" name="a">
转到页面二<input type="radio" name="a">
<input name="" type="submit" value="提交">
</form>
</body>
</html> 

以上这篇用JS动态改变表单form里的action值属性的两种方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

上一篇:js提交form表单,并传递参数的实现方法
下一篇:动态设置form表单的action属性的值的简单方法
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap