六、两个页面通过JS传值

 

传值页面(需通过页面跳转)

           
     var data = obj.data;
id=data.id

if (obj.event === 'edit') {
var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/table/edit.html?id='+encodeURI(id),
                });
                $(window).on("resize", function () {
                    layer.full(index);

                });
                return false;
            }

或(location.href)点击后的跳转页面地址,即本地地址改变

<input type="text" id="txt">
 
</br>
 
<input type="button" value="TEST" onclick="test()"/>
 
 
<SCRIPT LANGUAGE="JavaScript">
function
 test(){       
var s =document.getElementById("txt");
location.href="2.html?"+"txt="+encodeURI(s.value);
 }
 
</SCRIPT>

 

接收值页面

            var loc=location.href;//获取当前页面链接包括传的值(../page/table/edit.html?id=1)
            var n1=loc.length;//地址的总长度
            var n2=loc.indexOf("=");//取得=号的位置
            var idvalue=decodeURI(loc.substr(n2+1, n1-n2));//从=号后面的内容 值为1

 

posted on 2021-12-03 21:42  QiKS  阅读(252)  评论(0)    收藏  举报

导航