0

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

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

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



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

      }

刷新div后,不使用绿色。

4

3 回答 3

2

当你像这样添加颜色时:

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";
      }
于 2020-02-25T07:12:53.830 回答
0

您应该在刷新后再次应用 CSS 样式,因为它是动态应用的。当您刷新 div 时,浏览器将使用它包含的静态代码再次呈现它,这就是为什么不会应用动态添加的 css 的原因。

于 2020-02-25T06:59:59.427 回答
0

应该这样写。工作代码的链接在这里。

window.setInterval('refresh()', 1000);  
      function refresh() {
        $('#nav-tabContent').load(' #nav-tabContent')
      }
document.getElementById("sai").style.color = "green";
于 2020-02-25T07:07:34.003 回答