当前位置: 代码迷 >> JavaScript >> Js统制 form 提交到不同的action
  详细解决方案

Js统制 form 提交到不同的action

热度:79   发布时间:2012-11-03 10:57:42.0
Js控制 form 提交到不同的action

js控制form提交到不同action

我的环境是ssh

方法1<a href="<%=ctxPath%>/report/pointDetailsToExcel.do" ><img src='<%=ctxPath%>/image/admin/btn_search.gif'/>导出Excel</a></td>

?

?

这样可以实现跳转到 不同的action,但是在跳转到pointDetailsToExcel form参数没有传过去

因为它是<a href=“”> 并不是将同一个form 提交到另一个action 而只是相当于简单页面跳转一样!

方法2在将同一个form跳转到不同的action

<a href="#" onClick="mainForm.action='pointDetailsToExcel.do';mainForm.submit();"><img src='<%=ctxPath%>/image/admin/btn_search.gif'/>导出Excel</a>

或者这样写

?

?

<a href="#"

?

?

onClick="Redirect();">

?

?

<img src='<%=ctxPath%>/image/admin/btn_search.gif'/>导出Excel</a>

?

?

pointDetals.js中;

?

?

function Redirect(){

?

?

document.forms[0].action= "pointDetailsToExcel.do";

?

?

document.forms[0].submit();

?

?

}

?

?

方法3:在将同一个form跳转到不同的action的同时,传递一个新的 参数(并非原来form中的元素)

<a href="#"

?

?

onClick="Redirect(${cashCharge.id});">

?

?

<img src="<%=ctxPath%>/image/admin/btn_field.gif"/>

?

?

导出Eecel</a>

?

?

注意在传递的同时 传递一个id 但是页面的form元素中没有一个标签是对应的id

?

?

这样可以利用 隐藏域 处理要传递的 新的参数值

?

?

<input type="hidden" name="from1Id" id="from1Id"/>

?

?

在我的cashCharge.js

?

?

function Redirect(id){

?

?

document.form1.from1Id.value=id;//把获得id值赋值给fromId

?

?

document.form1.action= "cashChargeToExcel.do";

?

?

document.form1.submit();

?

?

}

?

?

然后在我的CashChargeToExcelAction.java

?

?

Private Integer fromId;

?

?

public Integer getFrom1Id() {

?

?

return from1Id;

?

?

}

?

?

?

?

?

public void setFrom1Id(Integer from1Id) {

?

?

this.from1Id = from1Id;

?

?

}

?

?

就可以获取跳转时传递的formId

  相关解决方案