您的位置:首页 > Web前端 > HTML

html中使用window.location.href()跳转和传递参数。

2018-02-02 12:40 585 查看
1.在按钮上添加onclick时间,并传递参数给js函数,参数可以为input中输入的值,也可以为jsp中获取的值。

onclick="searchInfo(form1.workername)"

在js函数里调用时要加.value

onclick="alterInfo(<%=work1.getCode()%>,<%=work1.getName()%>,<%=work1.getDetail()%>,<%=work1.getCount()%>)"

2.然后调用js中的函数实现跳转

function insert(){
window.location.href("workinsert.jsp");

}

function alterInfo(code,name,detail,count){
var string1 = code;
var string2 = name;
var string3 = detail;
var number = count;
window.location.href("alterInfo.jsp?code="+string1+"&name="+string2+"&detail="+string3+"&count="+number);

}

3.然后在跳转到的页面中使用request.getParameter()来获取参数

<%

  String code = request.getParameter("code");

  String name = request.getParameter("name");

  String detail = request.getParameter("detail");

  int count = Integer.parseInt(request.getParameter("count"));

 %>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: