简体   繁体   English

JavaScript中的CSS重要无法正常工作

[英]css in javascript important not working

I am trying to change the border color of any control in my page using javascript . 我正在尝试使用javascript更改页面中任何控件的边框颜色。 The color change but then returns back to the original color . 颜色更改,但随后又恢复为原始颜色。 first i tried : 首先我尝试了:

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

then I tried : 然后我尝试了:

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

also : 还:

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

finally : 最后:

 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);
 }

all of the above didnt work 以上所有都不起作用

any help ? 有什么帮助吗?

on submitting the page the color changes for a few seconds but then 'disappear' 提交页面时,颜色会改变几秒钟,但随后“消失”

You are changing the page, then submitting the form, then a new page loads, and the change you made to the old page is not in the new page. 您正在更改页面,然后提交表单,然后加载新页面,并且您对旧页面所做的更改不在新页面中。

You'll need to make the change in the new page too. 您还需要在新页面中进行更改。 Typically you'll want to do this by using server side code in your form handler. 通常,您将需要通过在表单处理程序中使用服务器端代码来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM