完全加载html后如何加载jquery片段?

时间:2016-04-05 04:52:19

标签: javascript jquery html reload

有没有办法在完全加载html后加载这些片段? 如果在js文件之后加载片段(设置为ASYNC加载)或甚至设置定时器,我会非常高兴。

var firstMove = 0;
var pictures = ['boar.jpg','lion.jpg','bones.jpg','eagle.jpg','wolf.jpg','boar.jpg','lion.jpg','bones.jpg','eagle.jpg','wolf.jpg','boar.jpg','lion.jpg','bones.jpg','eagle.jpg','wolf.jpg']
pictures.sort()
function replyClick(clicked_id)
{
  //if player already draw one card;
  if (firstMove){
    var image = document.getElementById(clicked_id);
    image.innerHTML = '<img src='+pictures[clicked_id-1]+' />'
    var firstPicture = document.getElementById(firstMove);
    if (image.innerHTML == firstPicture.innerHTML){
        firstMove=0;

    }
    else {
      image.innerHTML = "";
      firstPicture.innerHTML = "";
      firstMove=0
    }

  }
  // if player didnt draw any card;
  else {
    var image = document.getElementById(clicked_id);
    image.innerHTML = '<img src='+pictures[clicked_id-1]+' />'
    firstMove = clicked_id
  }
}


<div class="card" id="1" onclick="replyClick(this.id)"></div>
<div class="card" id="2" onclick="replyClick(this.id)"></div>

2 个答案:

答案 0 :(得分:1)

您将它们放在准备好功能的文档中,

$(document).ready(function(){$("#myModal11").modal('show');});

只需将最后一个放在准备好的功能上,你就可以了

虽然您也可以将其放入其中一个功能中:

$(document).ready(function(){
 // put all code here...
});

答案 1 :(得分:1)

您可以尝试此行为
希望这有帮助!

<html>
<head>

</head>
<body>

// My Html Here

<script>
$(document).ready(function(){
var modals = ['#bookings', '#studios', '#mygallery', '#social', '#reviews', '#articles', '#contactme', '#credits', '#pagemap', '#tsandcs', '#events'];
    if (window.location.hash && ~modals.indexOf(window.location.hash)) {
        $(window.location.hash).modal();
    }

$("#myModal11").modal('show');

$(".modal:not(.noclose) a").click(function(){
    $(this).closest(".modal").modal("hide");
    });
});

</script>
</body>

//并删除此单击功能并使用.on而不是单个处理程序

$(".modal:not(.noclose)").on("click","a",function(){
    $(this).closest(".modal").modal("hide");
    });
});