js 動態修改css檔案用到了cssRule,csscssrule
_.find(document.styleSheets[4].cssRules,function(cssRule){ if(cssRule.selectorText && cssRule.selectorText.indexOf(".navbar-fixed-top2")>-1){ cssRule.style.position=""; cssRule.style.top = "0px"; } if(cssRule.selectorText && cssRule.selectorText.indexOf("#pageIndi_content, #page1_l1_content, #page_appList") >-1){ cssRule.style.padding = "0px"; } if(cssRule.selectorText && cssRule.selectorText.indexOf("#page1_index_content") >-1){ cssRule.style.padding = "0px"; } });
迴圈用的underscore,在使用cssRule不能直接使用下面的代碼,否則不會生效
cssRule.style=" left: 0;position:'';right: 0; top: 0px;z-index: 1031;";
只能使用
cssRule.style.padding = "0px";
用js動態更改 css
$('li').each(function(){ if ( $(this).attr('value') == 'mm'){ $(this).addClass('yourClass') }})
怎才可以更改js檔案裡的css
如果你是不是想可以修改的js??
<script src="demo.jsp"></script>
<script src="demo.asp"></script>
<script src="demo.aspx"></script>
<script src="demo.php"></script>
相應的檔案裡面用相應代碼處理就可以
裡面的格式
respose 輸出 和js 檔案裡面的格式一樣就可以
不生效 就為空白就可以了!
<script src="demo.jsp?參數=值"></script>
可以用參數的形式做處理
靜態頁面話就沒辦法修改了
只能 直接修改js檔案
補充: 可以啊!!給<span id="spa"><script src="a.js"></script> </span>
//外面加個span
<script>
document.all.spa.innerHTML="";
</script>