简体   繁体   English

加载页面后如何调用函数自动执行

[英]How to call function auto execute after load page

I'm trying to create a slider dynamically with jQuery. 我正在尝试使用jQuery动态创建一个滑块。 I'm using an example from http://imageslidermaker.com/v2 , and have downloaded the source and copied to my js and css folders. 我正在使用http://imageslidermaker.com/v2中的示例,并已下载源代码并将其复制到我的jscss文件夹中。

My code: 我的代码:

<link rel="stylesheet" href="../css/my-slider.css"/>
<script src="../js/ism-2.0.1-min.js"></script>

        <div class="ism-slider" data-transition_type="fade" data-play_type="loop">
              <ul>
                    <li class="ism-slide-Imgs"><img src="../img/PuntaPalma/Suits-1.jpg" class="ism-img-Imgs"></li>
                    <li class="ism-slide-Imgs"><img src="../img/PuntaPalma/Suits-2.jpg" class="ism-img-Imgs"></li>
                    <li class="ism-slide-Imgs"><img src="../img/PuntaPalma/Suits-3.jpg" class="ism-img-Imgs"></li>
                    <li class="ism-slide-Imgs"><img src="../img/PuntaPalma/Suits-2.jpg" class="ism-img-Imgs"></li>
              </ul>
            </div>

with this example the js works fine, but when I try to dynamically add the images, the js does not work. 在此示例中, js工作正常,但是当我尝试动态添加图像时, js无法正常工作。

<div class="ism-slider" data-transition_type="fade" data-play_type="loop">
  <ul>
    <!--li append from jQuery ajax-->
  </ul>
</div>

Then I open the js and I see that it has a function auto execute, so the question is: How to do to execute the function that is inside of js after the page has loaded? 然后打开js ,然后看到它具有自动执行的功能,因此问题是:页面加载后如何执行js内部的功能?

Use onload. 使用onload。 Since you are using jq: 由于您正在使用jq:

$(window).load(function () {
    // do stuff
});

I took a look at this slideshow library, and found this which might be of interest to you: 我看了看这个幻灯片库,发现您可能感兴趣的这个:

<script>
    window.ISMConfig = {no_instantiation:true};
</script>
<script src="/ism/js/ism-2.0.1-min.js?v=150717"></script>

Not seeing your js source, there's a very simple jQuery method for it: 没有看到您的js源,有一个非常简单的jQuery方法:

$(document).ready(function(){ ... });

As soon as the document is finished loading, any functions pushed to the ready stack via this method will be called. 文档加载完成后,将立即调用通过此方法推送到ready堆栈的所有函数。

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

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