1. location.href =" " // 当前加载页面的完整URL
  2. location.search // 可设置或返回当前 URL 的查询部分(问号 ? 之后的部分)
  3. decodeURIComponent() //解码

music.html(跳转)

  1. <input type="text" id="input">
  2. <script>
  3. var input = document.getElementById("input")
  4. input.onkeydown = function(event){
  5. if(event.keyCode == 13){
  6. console.log(this.value);
  7. location.href = `search.html?s=${this.value}` //跳转到另一个页面
  8. }
  9. }
  10. </script>

search.html(传值)

  1. <p id="p">搜索</p>
  2. <script>
  3. console.log(location.search); // ?s=%E4%BD%A0%E7%9A%84
  4. var keyword = location.search.split("=")[1] // %E4%BD%A0%E7%9A%84
  5. var c = decodeURIComponent(keyword) // 解码
  6. p.innerHTML = c // 你的
  7. </script>