两个html页面之间怎样传参数

如题所述

html是静态页面,可以使用url链接传值,比如a.html和b.html两个页面

a.html中有一个链接

<a href="b.html?x=2&y=3">进入b.html</a>

可以使用到js,如下:

a.htm:

<form action="b.htm" >
<input name="q" type="text" value=""  />
<input type="submit" value="提交" id="" />
</form>

   

b.htm  

<html>
<body>
<div id="qbox"></div>
<script type="text/javascript">
function getArgs() { 
    var args = {};
        var query = location.search.substring(1);
         // Get query string
    var pairs = query.split("&"); 
                    // Break at ampersand
     for(var i = 0; i < pairs.length; i++) {
            var pos = pairs[i].indexOf('=');
             // Look for "name=value"
            if (pos == -1) continue;
                    // If not found, skip
                var argname = pairs[i].substring(0,pos);// Extract the name
                var value = pairs[i].substring(pos+1);// Extract the value
                value = decodeURIComponent(value);// Decode it, if needed
                args[argname] = value;
                        // Store as a property
        }
    return args;// Return the object 
 }
var str =getArgs();
alert(str['q']);//和input的name对应取值,
document.getElementById("qbox").innerHTML = str['q'];//然后赋值给DIV
</script>
</body>
</html>

    希望能帮到你哦!

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-06-17

1、首先在电脑打开eclipse软件。然后创建int参数age,赋值为21。代码:int age=21。

2、参见静态方法addAge(int a),内有参数a。

3、然后在addAge方法中,增加a增值的代码。

4、然后再从addAge方法中,输出a增加后的值。

5、然后在main方法中,将age的值传递给a。

6、然后在main方法中,输出数值传递之后的效果。

第2个回答  2016-07-23
通过服务器作为媒介 两个页面分别于服务器进行交互

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网