Heim  >  Artikel  >  Web-Frontend  >  JS控制表单提交的方法_javascript技巧

JS控制表单提交的方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 15:50:53943Durchsuche

本文实例讲述了JS控制表单提交的方法。分享给大家供大家参考。具体如下:

<Script Language="JavaScript">
function autoSubmit(){
var form = document.forms[0];
var actionPath = "&#63;mo=phone";
form.action = actionPath;
form.submit();
return true;
}
</Script>

如果需要两个提交按钮,type=""的属性值一个高为"submit"一个为"button",也就是一个用按钮本身提交,一个用JS控制提交

<form method="post" name="form1" id="form1" action="&#63;mo=phone&do=opreat" >
<input type="hidden" value="" name="phoneid" id="phoneid">
 <table border="0px" style="font-size:12px" width="630px" >
  <tr>
   <td align="right">手机型号:</td>
   <td><input type="text" id="phonetype" name="phonetype" style="width:120px" <&#63;# if $pinfo.pass_var.phonetype &#63;>value="<&#63;# $pinfo.pass_var.phonetype &#63;>" <&#63;# /if &#63;> /></td>
   <td><div id="phonetypeTip" style="width:250px"></div></td>
  </tr>
  <tr>
   <td align="right">类型:</td>
   <td><select name="type" id="type">
     <&#63;# foreach from=$types item=value &#63;>
  <option value="<&#63;# $value.type &#63;>"
  <&#63;# if $pinfo.pass_var.type== $value.type &#63;>selected="selected"<&#63;# /if &#63;>><&#63;# $value.type &#63;>
  </option>
  <&#63;# /foreach &#63;>
     </select></td>
   <td><div id="typeTip" style="width:250px"></div></td>
  </tr>
  <tr>
   <td align="right">厂商:</td>
   <td><select name="brandid" id="brandid">
     <&#63;# foreach from=$brand item=value &#63;><option value="<&#63;# $value.brandid &#63;>" <&#63;# if $pinfo.pass_var.brandid== $value.brandid &#63;>selected="selected"<&#63;# /if &#63;> ><&#63;# $value.name_zh &#63;></option><&#63;# /foreach &#63;>
     </select></td>
   <td><div id="brandidTip" style="width:250px"></div></td>
  </tr>
</table>
<input type="submit" value="增加手机" >
<input type="button" onclick="autoSubmit();" value="搜索手机" >
</form>

希望本文所述对大家的javascript程序设计有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn