我有一个使用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/