【问题标题】:How do I load jquery snippets after full load of html?完全加载html后如何加载jquery片段?
【发布时间】:2016-07-24 20:43:40
【问题描述】:

有没有办法在完全加载 html 后加载这些 sn-ps? 如果在 js 文件(设置为 ASYNC 加载)之后加载 sn-ps 甚至设置一个计时器,我会很高兴。

<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 个加载,最后一个需要文档就绪语句,如上所示

标签: javascript jquery html reload


【解决方案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");
    });
});

【讨论】:

  • 感谢分享,但它触发了“未捕获的 ReferenceError:$ 未定义”
【解决方案2】:

您正在将它们放入准备就绪功能的文档中,

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

只需将最后一个放在同一个就绪函数中,就可以开始了

尽管您也可以将它们放入其中一个函数中:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 2016-10-11
    相关资源
    最近更新 更多