gpt4 book ai didi

javascript - javascript 中的 css 重要不工作

转载 作者:太空宇宙 更新时间:2023-11-04 12:47:24 26 4
gpt4 key购买 nike

我正在尝试使用 javascript 更改我页面中任何控件的边框颜色。颜色改变但又恢复到原来的颜色。首先我试过:

control.style.border = "solid 1px red";

然后我尝试了:

control.attr('style', 'border : solid 1px red  ');

还有:

addStyleAttribute(control, 'border : solid 1px red  !important');

最后:

 var all = document.styleSheets,
s = all[all.length - 1],
l = s.cssRules.length;
if (s.insertRule) {
s.insertRule('#' + control.id+ ' {border: solid 1px red !important }', l);
}

以上都没有用

有什么帮助吗?

最佳答案

on submitting the page the color changes for a few seconds but then 'disappear'

您正在更改页面,然后提交表单,然后加载新页面,而您对旧页面所做的更改不在新页面中。

您还需要在新页面中进行更改。通常,您会希望通过在表单处理程序中使用服务器端代码来执行此操作。

关于javascript - javascript 中的 css 重要不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26400833/

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