[英]passing and retrieving Latin Character in URL query string
我有兩個HTML小號step1.html
和step2.html
和我傳遞拉丁值( envían
從) step1.html
送tep2.html
通過URL查詢字符串由具有傳遞值( envían
在輸入字段值)(在step1.html
處於隱藏狀態。
我正在使用某些實用程序功能在step2.html
獲取查詢字符串參數的值,並且在一個文本框中顯示該值,但在文本框中獲得的值與傳遞的值不同,請參見屏幕截圖。
獲得了í
編碼值,也幫助我在step2.html
獲得了相同的值í
。
編輯:一個缺點是step2.html
是twitter.com,那里我不能做任何解碼。 見下面的截圖
在此先感謝您的幫助。
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
</head>
<body>
<div class="">
<form action="step2.html">
<input type="submit" value="click to submit"/>
<input type="hidden" name="val" value="envían" />
</form>
</div>
</body>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<script>
var QueryString = function () {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
// If first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = pair[1];
// If second entry with this name
} else if (typeof query_string[pair[0]] === "string") {
var arr = [ query_string[pair[0]], pair[1] ];
query_string[pair[0]] = arr;
// If third or later entry with this name
} else {
query_string[pair[0]].push(pair[1]);
}
}
return query_string;
} ();
function fngetval(){
var val=QueryString.val;
document.getElementById("status").value=val;
}
</script>
<style>
</style>
</head>
<body onload="fngetval();">
<div class="">
<textarea id="status" name="status" ></textarea>
</div>
</body>
您不能在URL中使用í
,因此不能將其編碼為%ED
。
您可以1)使用POST
表單代替默認的GET
。 或2)解碼val
變量的值。 請參閱以下堆棧溢出問題: JavaScript URL解碼功能 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.