location.href =" " // 当前加载页面的完整URL location.search // 可设置或返回当前 URL 的查询部分(问号 ? 之后的部分) decodeURIComponent() //解码
music.html(跳转)
<input type="text" id="input"> <script> var input = document.getElementById("input")input.onkeydown = function(event){ if(event.keyCode == 13){ console.log(this.value); location.href = `search.html?s=${this.value}` //跳转到另一个页面 }}</script>
search.html(传值)
<p id="p">搜索</p><script> console.log(location.search); // ?s=%E4%BD%A0%E7%9A%84 var keyword = location.search.split("=")[1] // %E4%BD%A0%E7%9A%84 var c = decodeURIComponent(keyword) // 解码 p.innerHTML = c // 你的</script>