js解码

时间:2024-11-21 12:33:38

如代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<input type="text" id="input">
<button id="btn">click to html</button>
<script>
var btn=document.getElementById("btn");
var int=document.getElementById("input");
btn.onclick=function () {
open("others.html?"+int.value);
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
document.body.innerHTML=location.search.replace("?","");
</script>
</body>
</html>

结果图;

js解码js解码

search数据正常传入

当是中文的时候则

js解码

数据乱码

修改代码为

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<input type="text" id="input">
<button id="btn">click to html</button>
<script>
var btn=document.getElementById("btn");
var int=document.getElementById("input");
btn.onclick=function () {
var val=encodeURIComponent(int.value);
open("others.html?"+val+"");
console.log(val);
}
</script>
</body>
</html>
 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
document.body.innerHTML=decodeURIComponent(location.search).replace("?","");
</script>
</body>
</html>

效果

js解码