简体   繁体   English

无法在 ajax 加载的 div 中执行 javascript

[英]Can't execute javascript inside ajax loaded div

I'm using ajax to load some content inside a div, and this includes the jQueryVericalTabs plugin.我正在使用 ajax 在 div 中加载一些内容,这包括 jQueryVericalTabs 插件。 However the styles won't work an I just see the unformatted text.但是 styles 不起作用,我只看到未格式化的文本。

With FF's web developer tool I see that the rendered source is not linking to the styles on my CSS file despite being correctly called on the index page.使用 FF 的 web 开发工具,我看到渲染的源没有链接到我的 CSS 文件上的 styles,尽管在索引页面上被正确调用。 I tried writing the CSS directly on index.php, on the content file, putting it inside the body tags, with and without the javascript (per plugin's demo), and also the suggestion on this post but none worked, don't know what else to try.我尝试将 CSS 直接写在 index.php 上,在内容文件上,将其放在正文标签内,有和没有 javascript (每个插件的建议有效,但不知道这个帖子的建议是什么,但也不知道其他尝试。 Here's what my header looks like:这是我的 header 的样子:

<link rel="stylesheet" href="css/jquery-jvert-tabs-1.1.4.css" type="text/css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/jquery-jvert-tabs-1.1.4.js"></script>
<script type="text/javascript" src="js/ajax.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
        $(function(){
            $("#accordion").accordion({
                active: false,
                autoHeight: false,
                collapsible: true
            });
        });

    $("#vtabs5").jVertTabs({
        equalHeights: true
    });
    // add click events for open tab buttons
    $("input[id^=openTab]").each(function(index){
        $(this).click(function(){
            openTab("#vtabs6",index);
            return false;
        });
    }); 
    function openTab(tabId,index){
        $(tabId).jVertTabs('selected',index);
    }
});

I tried a different plugin, verticalTabs, and the tab-titles show with the correct formatting, but no tab-content is displayed.我尝试了一个不同的插件verticalTabs,并且选项卡标题以正确的格式显示,但没有显示选项卡内容。 I'd still prefer to use the first plugin though, the HTML is a lot cleaner.不过我还是更喜欢使用第一个插件,HTML 更干净。

I appreciate any input.我很感激任何意见。

Its just a suggestion, i have never tried it, but according to the jquery documentations, you can achieve and handle ajax loaded contents using .live() event.这只是一个建议,我从未尝试过,但根据 jquery 文档,您可以使用.live()事件实现和处理 ajax 加载的内容。 Check the documentation here.在此处查看文档。 Hope it helps and if you get an answer, please post it back希望对您有所帮助,如果您得到答案,请回帖

Thanks for your reply.感谢您的回复。 I solved it with the suggestion from this post , in case someone finds it useful:)我用这篇文章的建议解决了它,以防有人觉得它有用:)

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

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