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

时间:2021-04-04 21:15:14

Is there any way to load these snippets after full load of html? I'd be very happy if loading the snippets after the js file (set to ASYNC load) or even set a timer.

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

<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();}})</script>
<script>$(document).ready(function(){$("#myModal11").modal('show');});</script>
<script>$(".modal:not(.noclose) a").click(function(){$(this).closest(".modal").modal("hide");});</script>

2 个解决方案

#1


1  

You can try this Behaviour
Hope this helps !

你可以试试这个行为希望这有帮助!

<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>

// And Remove this click function and use .on instead of it for single handler

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

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

#2


1  

You are putting them in a document on ready function,

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

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

Just put the last one in that same on ready function and you're good to go

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

Although you could just put in them in one of those functions too:

虽然你也可以在其中一个函数中加入它们:

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

#1


1  

You can try this Behaviour
Hope this helps !

你可以试试这个行为希望这有帮助!

<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>

// And Remove this click function and use .on instead of it for single handler

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

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

#2


1  

You are putting them in a document on ready function,

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

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

Just put the last one in that same on ready function and you're good to go

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

Although you could just put in them in one of those functions too:

虽然你也可以在其中一个函数中加入它们:

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