javascript - 刷新 div 后 CSS 样式不起作用
问题描述
我正在尝试使用 jQuery 刷新 div,但刷新我的 CSS 后不起作用。
仅供参考:我动态设置 CSS,
document.getElementById("sai").style.color = "green";
window.setInterval('refresh()', 1000);
function refresh() {
$('#nav-tabContent').load(' #nav-tabContent')
}
刷新div后,不使用绿色。
解决方案
当你像这样添加颜色时:
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";
}
推荐阅读
- java - 如何返回 Collection 子类型而不是抽象 Collection?
- sql - 由于 SQL 中的分页,子记录被跳过
- python - 根据列值复制行并修改列值
- c# - 在 C# .NET 中使用 HTTPClient 调用 POST API 时不会给出任何结果或错误
- python - pd.read_html 不适用于多个网址。IndexError:列表索引超出范围
- python - 根据来自 forloop 的不同函数调用返回的值构建数据框
- firefox - 使用 gst (ts m3u8) 生成的 hls 不在 safari 上播放(但在 chrome 上工作)
- java - java - Spring框架中Collection的可能竞态条件
- qt - qt 5.15 静态构建中的 QML Svg,使用 CMake
- python - pywinauto print_control_identifier() 显示元素但无法使用 ElementNotFoundError 获取它