在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ JS 值傳遞問題,求解決

JS 值傳遞問題,求解決

現(xiàn)在有兩個頁面,分別記作頁面A和頁面B,這兩個頁面分別對應兩個JS文件:a.js 和 b.js,現(xiàn)在要在 a.js 中獲取到頁面A的URL,然后把這個值傳遞給b.js,讓b.js獲取到這個URL值并使用它,這個應該怎么實現(xiàn)啊?比較著急,希望路過的大神給指教下。

回答
編輯回答
夢囈

2種方式:

  1. URL參數(shù)傳遞,在A頁面添加上參數(shù),然后在B頁面獲取url中的參數(shù)
  2. cookie或localStorage,在A頁面存儲數(shù)據(jù),在B頁面獲取數(shù)據(jù)
2017年10月16日 19:16
編輯回答
失心人

a頁面 window.location.href ='b.html?name=xx'
b頁面 window.location.href 獲取URL

2018年6月10日 08:45
編輯回答
萌二代

可以利用H5的 localStorage
A頁面:localStorage.setItem('myUrl',location.href)
B頁面:localStorage.getItem('myUrl')

2017年10月31日 00:00
編輯回答
蔚藍色

在url上傳遞,b.html?param=A上獲取的值

2017年3月31日 13:24
編輯回答
安于心

謝謝樓上各位的幫助,目前我采用的是h5的localstorage來解決的這個問題。

2017年8月16日 12:02
編輯回答
巫婆
<a href="b.html" id="aPage">在url里帶數(shù)據(jù)跳轉(zhuǎn)到b頁面</a>
<script>
        $(document).ready(function() {
            // 拼接跳轉(zhuǎn)url中要傳輸?shù)臄?shù)據(jù)
            var dataUrl = [];
            dataUrl.push('feng');
            dataUrl.push('xin');

            $('#aPage').on('click',function(){
                $('#aPage').attr("href","b.html?data=" + dataUrl);
            })
        });
    </script>
<input type="text" id="getUrlData">
 <script>
        $(document).ready(function() {
            //使用正則表達式獲取url中的參數(shù)
            function getUrlParam(name) {
                //構(gòu)造一個含有目標參數(shù)的正則表達式對象
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                //匹配目標參數(shù)
                var r = window.location.search.substr(1).match(reg);

                console.log(window.location.search);
                //返回參數(shù)值
                if (r != null) return unescape(r[2]); return null;
            }
            var urlData = getUrlParam('data');
            // 將數(shù)據(jù)填充到input框里面
            $('#getUrlData').val(urlData);
        });
    </script>
2018年5月1日 23:23