在js中window.open通过“post”传递参数

在js中window.open通过“post”传递参数的步骤如下:

如:在A.jsp中 有一个js方法 winow.open,目标地址是 xx.do

1、在A.jsp建一个form,把要设置的值通过js动态添加到里面,如:

$("#postForm").append('<input type="hidden" name="query.id" value="12"/>');
2、设置form的target属性:
$("#postForm").attr("target","newWin");
3、设置form的action:
$("#postForm").attr("action","<%=path%>/xx/xx.do");
4、window.open:
window.open("about:blank","newWin","");//newWin 是上面form的target
5、提交表单:
$("#postForm").submit();

ok,完成上面5步之后,完整的js方法如下:

function openWin(){
   $("#postForm").html('');//防止元素重复
   $("#postForm").append('<input type="hidden" name="query.id" value="12"/>');
   $("#postForm").attr("target","newWin");
   $("#postForm").attr("action","<%=path%>/xx/xx.do");
   window.open("about:blank","newWin","");//newWin 是上面form的target
   $("#postForm").submit();
}

转载自http://www.thinksaas.cn/news/show/431/
posted @ 2014-09-02 19:33  tancp  阅读(3592)  评论(0编辑  收藏  举报