在加载我的页面之前,我想对类样式进行一些修改。
样式类包含在 MyStyle.css
.divNew {
float: left;
margin: 10px 5px 5px 25px;
}
加载新页面我想修改/重载边距并添加高度。 有什么建议吗? 这是我试过的:
function pageLoad() {
var theRules = new Array();
if (document.styleSheets[0].cssRules) {
theRules = document.styleSheets[0].cssRules;
} else if (document.styleSheets[0].rules) {
theRules = document.styleSheets[0].rules;
}
for (n in theRules) {
if (theRules[n].selectorText == 'divNew') { ? ? ? ?
}
}
}
最佳答案
使用 jQuery on Document ready 你可以做这样的事情。
$(document).ready(function(){
$('.divNew').css('margin','modifications'); // .css('margin','10px 10px 10px 10px');
$('.divNew').height(newHeight); // .height(300)
});
供引用
关于javascript/jquery修改一个css类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19771598/