路由

路由:根据url地址不同,给用户呈现不同的界面(html)


music.html**

  1. <input type="text" id="input" value="你">
  2. <!--
  3. 1.如何跳转到search
  4. 2.如何传值
  5. -->
  6. <script>
  7. var input = document.getElementById("input");
  8. input.onkeyup = function(event){
  9. if(event.keyCode == 13){
  10. console.log(this.value);
  11. location.href = `search.html?s=${this.value}`
  12. }
  13. }
  14. </script>

search.html

  1. <p>搜索</p>
  2. <script>
  3. console.log(location.search.split("=")[1])
  4. var keyword = location.search.split("=")[1];
  5. var c = decodeURIComponent(keyword);
  6. console.log(c);
  7. </script>