使用数据激活和jQuery load() [英] Work with data-activates and jQuery load()

查看:53
本文介绍了使用数据激活和jQuery load()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在尝试在我的每个页面上打开导航栏。



Hello,

I'm trying to open a nav bar below on every page I have.

<nav>
    <ul id="slide-out" class="side-nav fixed">
        <li><a href="index.html">index</a></li>
        <li><a href="about.html">about</a></li>
        <li><a href="news.html">news</a></li>
        <li><a href="hybrids.html">hybrids</a></li>
        <li><a href="puppies.html">puppies</a></li>
    </ul>
    <a href="#" data-activates="slide-out" class="button-collapse"></a>
</nav>





在我用Jquery调用html文件加载到标头标签:





For that I'm calling the html file with Jquery to load into the header tag:

$().ready(function () {
   $("header").load("master.html");
});





我注意到的一件事是滑出效果不起作用。经过研究,我发现jQuery的加载方法从html剥离脚本(如果我错了,请纠正我)。有人建议再次加载脚本,但它不起作用。我认为它与data-activates属性/属性有关,但是我找不到很多关于它的信息。



有没有人有这个问题?你是怎么解决的?



One thing I noticed is that the "slide out" effect is not working. After researching, I've found out that jQuery's load method "strips away" the script from html (please correct me if I'm wrong). Some suggested loading the script again, but it didn't work. I think it has something to do with the data-activates property/attribute, but I can't find much information about it.

Has anyone had this issue? how did you solve it?

推荐答案

()。ready( function (){
().ready(function () {


header)。load( master.html);
});
("header").load("master.html"); });





我注意到的一件事是滑出效果不起作用。经过研究,我发现jQuery的加载方法从html剥离脚本(如果我错了,请纠正我)。有人建议再次加载脚本,但它不起作用。我认为它与data-activates属性/属性有关,但是我找不到很多关于它的信息。



有没有人有这个问题?你是如何解决它的?



One thing I noticed is that the "slide out" effect is not working. After researching, I've found out that jQuery's load method "strips away" the script from html (please correct me if I'm wrong). Some suggested loading the script again, but it didn't work. I think it has something to do with the data-activates property/attribute, but I can't find much information about it.

Has anyone had this issue? how did you solve it?


经过大量的试验和测试并让我的同行参与到这个问题中。我们注意到html文件只是在为标签分配事件的脚本之后才加载。



为了解决这个问题,我将调用改为:



After a lot of trials and tests and getting my peers involved into the issue. We noticed that the html file was loading only after the scripts that assigned events to the tags.

To fix this I changed the call to:


这篇关于使用数据激活和jQuery load()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆