在JavaScript中,页面之间如何传值

JavaScript010

在JavaScript中,页面之间如何传值,第1张

可以利用form表单提交获取上一个页面的值

例:form表单提交传值及取值

发请求页面

<form style="display: none" method="post"

       id="infoDetailsHyperlink" name="input"

       action="<%=request.getContextPath()%>/view/basicmanage/reportTemplet/positionPeopleConfig.jsp">

       <input name="infoId" id="infoId">

       <input name="operationType" id="operationType">

       <input name="copyTempletIdConfigPeople" id="copyTempletIdConfigPeople">

</form>

发请求页面,js中发送请求

$("#infoId").val($("#lastStepTempletId").val())

$("#operationType").val($("#operationTypeIdLastStep").val())

$("#infoDetailsHyperlink").submit()

接收页面

<input  id="infoId" style="display: none"  value=<%=request.getParameter("infoId")%>>

<input  id="operationType" style="display: none"   value=<%=request.getParameter("operationType")%>> 

<input  id="copyTempletIdConfigPeople" style="display: none"   value=<%=request.getParameter("copyTempletIdConfigPeople")%>>

<script>

<%request.setCharacterEncoding("utf-8")%>     解决传值时中文乱码问题

</script>

只说一下思路:

用URL记录传值

<a href='Specific.aspx?idStr=val1&name=name1&sex=sex1</a>

因为url后面的?不会影响连接指向,所以可以传递参数。这只是简单的例子,真正实现还需要现场操作。

用缓存cookie记录传值

var oDate=new Date()

oDate.setDate(oDate.getDate()+iDay)

document.cookie=name+'='+value+'path=/expires='+oDate.toGMTString()

将值暂存到cookie中,让后再用document.cookie再取出数据。

window.name

var myWindow

function openWin()

{

myWindow=window.open('','MsgWindow','width=200,height=100')

myWindow.document.write("<p>This window's name is: " + myWindow.name + "</p>")

}

</script>

</head>

<body>

<input type="button" value="Open 'myWindow'" onclick="openWin()" />

点击后就会弹出你保存的Msgwindow的值。这样就实现了夸页面去数据。