在WebBrowser里执行JS脚本操作CSS

function BIdName(sname)
{ 
   return document.getElementById(sname).style;
}
function BClassName(sname)
{ 
    for (var i=0;i<document.styleSheets.length;i++)
    { 
    var rules; 
    if (document.styleSheets[i].cssRules)
    { 
    rules = document.styleSheets[i].cssRules; 
    }
    else
        { 
         rules = document.styleSheets[i].rules; 
        } 
    for (var j=0;j<rules.length;j++)
        { 
        if (rules[j].selectorText == sname)
            { 
            return rules[j].style; 
            }
        }
    }
}

BClassName(".top").display = "none"; //操作class的CSS
BIdName("beitou").display = "none"; //操作ID的CSS 不要带#

 

posted @ 2013-03-19 13:28  banbu  阅读(2218)  评论(0编辑  收藏  举报