巧用js提交表单轻松解决一个页面有多个提交按钮

复制代码 代码如下:

  <pre class="javascript" name="code">function check(txt){

  $j("form").submit(function(){

  if($txt=="提交"){

  this.action="doAddMessage.action?button=提交";

  this.submit();

  }else{

  this.action="doAddMessage.action?button=保存";

  this.submit();

  }

  });

  }</pre><br>

  <input type="IMAGE" src="style/blue/images/button/send.png" name="button" value="提交" onclick="check(this)"/><input type="IMAGE"src="style/blue/images/button/saveToDraftBox.png" name="button" value="保存" onclick="check(this)"/>

  <pre></pre>

  <p><br>

  例如:页面中有两个图片按钮的提交,我们这个时候可以给他们都绑定onclick事件,这个时候我们借助jquery的form表单有个事件,叫做submit的。</p>

  <p>如图,由于,我的项目里面用了dwr,我把jquery的控制权转让给dwr,jquery重新指定 了一个$j,我们获取表单,然后使用submit事件,通过判断value的值,从而可以进行多个页面的跳转。</p>

  <p> </p>

  <p> </p>