gpt4 book ai didi

javascript - modernizr 和 ajax 加载冲突

转载 作者:行者123 更新时间:2023-11-29 22:07:31 25 4
gpt4 key购买 nike

我有一个页面使用 modernizr.js 和一个自定义的 ajax 函数,每 x 秒重新加载一次页面内容。这是触发函数的代码。

function reloadSlides() {
jQuery.ajax({
url: document.location.href,
cache: true,
success: function(html){
jQuery('#main').html(html);
}
});
}

当我查看 DOM 检查器时,这些类开始在 HTML 标记中一次又一次地重复,如下所示:

html lang="de" class=" js no-touch cssanimations csstransitions js no-touch cssanimations csstransitions js no-touch cssanimations csstransitions js no-touch cssanimations csstransitions js no-touch cssanimations csstransitions js no-touch cssanimations csstransitions" style=""

这是为什么呢?我怎样才能避免这种情况?

感谢您的关注!

最佳答案

在我看来,您正在重新加载 ID 为 main 的元素内的整个页面。

jQuery('#main').html(html);

这将获取所有重新加载的 html 并将其填充到所选元素中。尝试只重新加载 main 中的内容而不是所有内容。

关于javascript - modernizr 和 ajax 加载冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20082804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com