由于基于 IE9 中三个条件的聚合页脚对齐方式的更改,我正在尝试更改 gridview 页脚样式的样式,但它只是不断向我抛出未定义的错误,我的问题是如何更改样式有任何帮助值得赞赏:
.rgFooter, .rgFooterDiv
{
background: none !important;
background-color: transparent !important;
width: 100% !important;
/*max-width:779px;*/
}
致:
.rgFooter, .rgFooterDiv
{
background: none !important;
background-color: transparent !important;
width: 100% auto!important;
}
仅使用 javascript,不使用 JQuery。到目前为止我尝试过:
var mydiv = document.getElementById("mygrid").className;
mydiv.setAttribute("style", "width: 100% auto !important; background: none !important; background-color: transparent !important;");
感谢大家的帮助
最佳答案
如果您无法使用 jQuery,也许您应该只使用其中的 addClass
和 removeClass
函数。你可以在这里看到它们用纯 JavaScript 重写:https://stackoverflow.com/a/14105067/1026459
您对 setAttribute
的调用不起作用的原因是您所做的引用是对元素类的字符串。
var mydiv = document.getElementById("mygrid").className;
也许您应该像这样访问 div:
var mydiv = document.getElementById("mygrid");
然后您将可以访问setAttribute
。要简单地从 div 中删除所有类,您可以随时使用
mydiv.removeAttribute("class");
关于javascript - IE 9 通过 Javascript 设置样式属性,不使用 JQuery 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14697929/