首页 > 解决方案 > 刷新 div 后 CSS 样式不起作用

问题描述

我正在尝试使用 jQuery 刷新 div,但刷新我的 CSS 后不起作用。

仅供参考:我动态设置 CSS,

document.getElementById("sai").style.color = "green";



window.setInterval('refresh()', 1000);  
      function refresh() {
        $('#nav-tabContent').load(' #nav-tabContent')

      }

刷新div后,不使用绿色。

标签: javascriptjqueryhtml

解决方案


当你像这样添加颜色时:

document.getElementById("sai").style.color = "green";

您将其添加为内联样式。

当您再次重新渲染 div 时,您添加的内联样式会动态消失。您应该color在此操作之后再次添加,如下所示:

window.setInterval('refresh()', 1000);  
      function refresh() {
        $('#nav-tabContent').load(' #nav-tabContent');
        document.getElementById("sai").style.color = "green";
      }

推荐阅读