導航:首頁 > 編程語言 > js獲取url中文參數

js獲取url中文參數

發布時間:2021-04-02 06:49:36

js獲取參數遇漢字變成url碼了,如果解決

使用decodeURI() 函數可對 encodeURI() 函數編碼過的 URI 進行解碼。
代碼專中的this[name] = value;修改成屬this[name] = decodeURI(value);即可。

② 利用JS獲取地址欄的中文參數,如何避免取到亂碼

地址欄的URL不同的瀏覽器的行為不太一樣,有的會按歸照GB編碼編碼成%A1%A1這種形式回,有的會按照UTF-8編碼,直接輸答入URL和點擊鏈接訪問的URL也可能不一樣。
這樣js取值的時候會出現字元集的問題。
建議還是修改ASPX文件,取到值以後生成js時賦值給某個變數。

③ 如何把js獲取url中文亂碼轉碼

一:Js的Url中傳遞中文參數亂碼問題,重點:encodeURI編碼,decodeURI解碼:1.傳參頁面javascript 代碼內:<script type=」text/ javascript 」>// <![CDATA[function send(){var url = "test01.html";var userName = $("#userName").html();window.open(encodeURI(url + "?userName=" + userName)); }// ]]>

④ Js的Url中傳遞中文參數亂碼,如何獲取Url中參數問題

先編碼 接收端在解碼,escape,你查一下手冊!

⑤ js獲取地址欄中參數值是中文的該怎麼獲取

decodeURI()這個函數可以幫你編碼過的URL解碼。

⑥ 如何用JS獲取連接url中的相關參數

使用split切分法

functionGetRequest(){
varurl=location.search;//獲取url中"?"符後的版字串
vartheRequest=newObject();
if(url.indexOf("?")!權=-1){
varstr=url.substr(1);
strs=str.split("&");
for(vari=0;i<strs.length;i++){
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
}
}
returntheRequest;
}

⑦ 如何把js獲取url中文亂碼進行轉碼

一:Js的Url中傳遞中文參數亂碼問題,重點:encodeURI編碼,decodeURI解碼:1.傳參頁面Javascript 代碼:<script type=」text/ javascript 」>// <![CDATA[function send(){var url = "test01.html";var userName = $("#userName").html();window.open(encodeURI(url + "?userName=" + userName)); }// ]]>

⑧ JS 傳遞URL帶中文的參數

escape改成encodeURIComponent

// var url = "qreg.php?ss_bzn=" + escape(ss_bzn);

var url = "qreg.php?ss_bzn=" + encodeURIComponent(ss_bzn);

⑨ js獲取中文參數跳轉時亂碼

那不叫亂碼,而抄是url編碼,js本身就是讀取url編碼的
對於js獲取url的中文可以嘗試用escape() encodeURI() encodeURIComponent() decodeURI()
來使js停止或者轉換url編碼

⑩ js如何獲取請求中的url以及參數

方法一、正則表達式
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
方法二、
<Script language="javascript">
function GetRequest() {
var url = location.search; //獲取url中"?"符後的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
</script>
方法三、
/**
* 獲取指定的URL參數值
* URL:http://www.quwan.com/index?name=tyler
* 參數:paramName URL參數
* 調用方法:getParam("name")
* 返回值:tyler
*/
function getParam(paramName) {
paramValue = "", isFound = !1;
if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
}
return paramValue == "" && (paramValue = null), paramValue
}
其他參數獲取介紹:
//設置或獲取對象指定的文件名或路徑。
alert(window.location.pathname);
//設置或獲取整個 URL 為字元串。
alert(window.location.href);
//設置或獲取與 URL 關聯的埠號碼。
alert(window.location.port);
//設置或獲取 URL 的協議部分。
alert(window.location.protocol);
//設置或獲取 href 屬性中在井號「#」後面的分段。
alert(window.location.hash);
//設置或獲取 location 或 URL 的 hostname 和 port 號碼。
alert(window.location.host);
//設置或獲取 href 屬性中跟在問號後面的部分。
alert(window.location.search);

閱讀全文

與js獲取url中文參數相關的資料

熱點內容
cad文件為什麼顯示文件名是否正確 瀏覽:174
程序配置文件能自動轉換成txt 瀏覽:985
r4燒錄卡不同版本 瀏覽:962
怎麼升級qq群為2000 瀏覽:347
微信己冊除的文件怎樣找回來 瀏覽:715
蘋果美國賬號共享2017 瀏覽:252
ps文件修改後打開還是原圖 瀏覽:220
燒卡機蘋果4微信qq哪裡下載 瀏覽:780
ug120找不到指定文件 瀏覽:522
cda文件怎麼轉換成mp3格式 瀏覽:702
青島hpv疫苗在哪個app預約 瀏覽:881
雙十一成交額2021數據在哪裡看 瀏覽:631
蘋果手機怎麼打開移動數據 瀏覽:637
文件掃描成圖片是彩色的嗎 瀏覽:50
編程里的comply什麼意思 瀏覽:91
電腦上面點了禁用網路怎麼改回來 瀏覽:28
javacatch執行 瀏覽:182
ps軟體文件名字 瀏覽:184
黑蘋果查找文件路徑 瀏覽:397
現在編程都有哪些語言 瀏覽:360

友情鏈接