如代码:
<!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>
结果图;
search数据正常传入
当是中文的时候则
数据乱码
修改代码为
<!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>
效果