主页 M

2个纯Html之间的传值方法

2017-06-29 网页编程网 网页编程网

index.html页面

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT>
    function show(){
        var result = document.getElementByIdx("name").value;
        location.href="index2.htm?name="+result;
    }
</SCRIPT>
</HEAD>
<BODY>
<input type="text" id="name" class="input7">
<input type="button" value="OK" onclick="show()"/>
</BODY>
</HTML>

index2.htm

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT>
function getvalue(name){
    var str=window.location.search;   //location.search是从当前URL的?号开始的字符串
      if (str.indexOf(name)!=-1){        
        var pos_start=str.indexOf(name)+name.length+1;
        var pos_end=str.indexOf("&",pos_start);
        if (pos_end==-1){
            alert( str.substring(pos_start));
        }else{
            alert("没有此值~~");
        }
    }
}
</SCRIPT>
</HEAD>
<BODY>
<input type="button" onclick="getvalue('show')" value="GetValue"/>
</BODY>
</HTML>
阅读原文
阅读 6369
123 显示电脑版