跳转传值:

1、location.href =xxx.html?s=${value}

2、<a href="xxx.html?s=${value}"> </a>

3、事件传值:

取值:

在location里找值:location.search.split(“=”)[1]

decodeURIComponent():如果接到的是中文需要转码成中文

eg:

传值music.html:

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

接收值search.html:

    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<body>
    <p id="p">搜索</p>
    <script>
    console.log(location.search.split("=")[1]);  //
     var keyword = location.search.split("=")[1];
     var c = decodeURIComponent(keyword);
     console.log(c);  //中文
     $("p").empty();
     $("p").append(c);
    </script>
</body>

eg:a标签跳转

<body>
    <div class="content">

            <div class="img">
                <img src="" alt="">
            </div>
            <p class="name">我们终于放下了</p>
            <p class="actor">许亚童</p>
        </div> -->
    </div>
    <script>
        var url = "http://192.168.4.18:3000/top/album";
        ajax({
            url:url,
            method:"get",
            success:res=>{
                // var arr = res.albums;
                var arr = res.playlists;
                arr.forEach(item=>{
                     var {name,creator,coverImgUrl} =item
                    var actors = creator.nickname;  
                   var famplate = `
                   <a href="html/detail.html?id=${item.id}">     
                   <div class="music">
                       <div class="img">
                           <img class="image" src=${coverImgUrl} alt="">
                       </div>
                       <p class="name">${name}</p>
                       <p class="actor">${actors}</p>
                   </div>
                   </a>
                   `
                   $(".content").append(famplate);
                })
            }
        })
    </script>
</body>

eg:事件传值

    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>

<body>
    <div class="item" data-aid="1234">
        hello world1
    </div>
    <div class="item" data-aid="1235">
        hello world2
    </div>
    <script>
        $(".item").click(function(event){
            console.log(event.target.dataset.aid);
        })
    </script>
</body>