<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [toc] ## 查看當前location對象 ``` console.log(location); ``` ![](https://box.kancloud.cn/53eca8fcbbfd976ca7e375661d94f6f1_338x291.png) ``` function showLoc() { var oLocation = window.location, aLog = ["Property (Typeof): Value", "window.location (" + (typeof oLocation) + "): " + oLocation ]; for (var sProp in oLocation){ aLog.push(sProp + " (" + (typeof oLocation[sProp]) + "): " + (oLocation[sProp] || "n/a")); } alert(aLog.join("\n")); } showLoc(); ``` ## location和location.href和location.assign() MDN文檔中說`window.location`這貨是個只讀屬性,但又說這貨可以被賦值。。。 emmm...你別聽它的 除此之外`window.location=`和`window.location.href=`和`window.location.assign()`是等價的 ### href支持hash 且如果賦的是一個hash值(比如`#123`),它會自動識別,并在原本的location地址末尾追加上(`原先的地址#123`) ## location.reload:強制從服務器重新加載當前頁面 ``` window.location.reload(true); ``` ## location.replace ``` function reloadPageWithHash() { var initialPage = window.location.pathname; window.location.replace('http://example.com/#' + initialPage); } ``` ## location.search:向當前服務器地址發送query ![](https://box.kancloud.cn/c734e64bbca2af456680a153c779b245_538x128.png) ``` function sendData (sData) { window.location.search = sData; } ``` ### 封裝一個query對象 ``` var oGetVars = {}; if (window.location.search.length > 1) { for (var aItKey, nKeyId = 0, aCouples = window.location.search.substr(1).split("&"); nKeyId < aCouples.length; nKeyId++) { aItKey = aCouples[nKeyId].split("="); oGetVars[decodeURIComponent(aItKey[0])] = aItKey.length > 1 ? decodeURIComponent(aItKey[1]) : ""; } } // alert(oGetVars.yourVar); ``` 同樣可以通過一個匿名構造函數來獲取,這樣只聲明了一個全局變量。 ``` var oGetVars = new (function (sSearch) { if (sSearch.length > 1) { for (var aItKey, nKeyId = 0, aCouples = sSearch.substr(1).split("&"); nKeyId < aCouples.length; nKeyId++) { aItKey = aCouples[nKeyId].split("="); this[decodeURIComponent(aItKey[0])] = aItKey.length > 1 ? decodeURIComponent(aItKey[1]) : ""; } } })(window.location.search); // alert(oGetVars.yourVar); ``` ### 獲取query對象中的鍵值 ``` function loadPageVar (sVar) { return decodeURI(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + encodeURI(sVar).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1")); } alert(loadPageVar("name")); ``` ### 更多請查看MDN case 8: ... [MDN](https://developer.mozilla.org/zh-CN/docs/Web/API/Window/location)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看