简体   繁体   English

链接点击只工作一次

[英]link click works only once

i have hidden div that contain a div inside it and this div is hidden by default , and i have link should bring the content of (#mobiles_thumbs) div , every thing work perfectly just for first click on the link and the second click the div that change its content disappear i used (on) delegate .我有一个隐藏的 div,其中包含一个 div,默认情况下这个 div 是隐藏的,我有链接应该带来 (#mobiles_thumbs) div 的内容,每件事都可以完美运行,只需第一次点击链接,第二次点击 div改变它的内容消失了我使用(在)委托。 this is my code :这是我的代码:

 //and here my jquery code for handle the link click : $('#products').on('click', 'a', function() { $("#thumbs").html($("#thumbs_collection #mobiles_thumbs")); /* here #thumbs_collection is the name of big div that contain six div inside it. */ });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <!-- this is the hidden div --> <div id="thumbs_collection"> <div id="mobiles_thumbs" style="visibility:hidden"> <img alt="mobile1" src="images/mobile1.jpg"> <img alt="mobile2" src="images/mobile2.jpg"> </div> </div> <div id="products" class="container-fluid"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <h1>Our Products </h1> </div> <div class="col-sm-12"> <ul> <li> <a href="#mobiles"> Mobiles </a></li> <li> <a href="#swatches"> Swatches </a></li> <li> <a href="#chairs"> Chairs </a></li> <li> <a href="#boxs">Boxs </a></li> <li> <a href="#Doors"> Doors </a></li> <li> <a href="#windows"> Windows </a></li> </ul> </div> <div id="thumbs"> <!--this div for load the products --> </div> </div> </div>

Try cloning the element fist and don't forget to toggle visibility after the html append尝试克隆元素拳头,不要忘记在 html 追加后切换可见性

var temp = $("#thumbs_collection #mobiles_thumbs").clone();
$('#products').on('click', 'a', function() {
  $("#thumbs").html(temp);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM