在JavaScript中将值从一个页面传递到另一个页面 [英] Passing values from one page to another in JavaScript

查看:107
本文介绍了在JavaScript中将值从一个页面传递到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

 <!DOCTYPE html>在下面的代码中,值不会从一个页面传递到另一个页面。 
< html xmlns =http://www.w3.org/1999/xhtml>
< script type =text / javascript>

函数generateRow(){
var myvar =testuser;

'<%Session [temp] ='+ myvar +'; %GT;;
window.location =WebForm2.aspx;
}
< / script>
< head>
< title>< / title>
< / head>
< body>
< div runat =server>
< input id =Button1type =buttononclick =generateRow()value =button/>
< / div>

< / body>
< / html>

上述代码有什么问题?

解决方案

您无法使用Javascript设置会话。您输出的JS文件将与您写下的内容完全一致。



您可以这样做:

  window.location =WebForm2.aspx?temp =+ myvar; 

在Webform2中,您可以这样做:

 的Request.QueryString [ 临时]; 


In below code, the value is not passed from one page to another.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<script type="text/javascript">

    function generateRow() {
        var myvar = "testuser";

        '<%Session["temp"] = "' + myvar +'"; %>';
        window.location = "WebForm2.aspx";
    }
</script>
<head>
    <title></title>
</head>
<body>
    <div runat="server">
        <input id="Button1" type="button" onclick="generateRow()" value="button" />
    </div>

</body>
</html>

What is the problem in above code?

解决方案

You cannot set a session with Javascript. Your output JS file will be exactly what you wrote down.

You can do it like this:

window.location = "WebForm2.aspx?temp=" + myvar;

And in Webform2 you can do:

Request.querystring["temp"];

这篇关于在JavaScript中将值从一个页面传递到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆