2013-06-28 2 views
3

자바 스크립트를 통해 CSS 클래스를 편집 할 수 있도록 일부 도우미 함수를 작성하려고합니다. 여기에 제가 가지고있는 것이 있습니다 만, 왜 그것이 "정의되지 않은"상태로 돌아가는지 이해하지 못합니다. 크롬 사용 테스트.이 함수가 CSS 규칙을 반환하지 않는 이유는 무엇입니까?

function getRule(name, doDelete) { //takes a rule name and boolean 

    if(document.styleSheets) { //check if there are stylesheets 

     for(var i = 0; i < document.styleSheets.length; i++) { //loop through style sheets 

      var currentSheet = document.styleSheets[i]; 
      if(currentSheet.cssRules) { //if the sheet has rules 

       for(var h = 0; h < currentSheet.cssRules.length; h++) { //loop through css rules 

        var currentRule = currentSheet.cssRules[h]; 
        if(currentRule.selectorText == name) { //if rule name is equal to the name given 

         return currentRule; //return the css rule 

        } 

       } 

      } 

     } 

    } 

} 

CSS를 사용 : 이러한 문제의

.menuopen { 

    margin-left: auto; 
    margin-right: auto; 
    text-align: center; 
    font-size: 20px; 
    width: 960px; 
    height: 200px; 
    background-color: 3b7ea8; 
    box-shadow: inset 0px 2px 5px 3px rgba(0,0,0,0.75); 
    -webkit-animation-name: dropAnimation; 
    -webkit-animation-duration: 2s; 

    } 
+0

어떻게 규칙을 검색하고 있습니까? 방금 피들을했고 코드가 작동하는 것 같습니다! http://jsfiddle.net/kA24S/2/ – Thanizer

+0

정말요? Chrome에서 사용하고 있으며 getRule (". dropmenu")을 입력했는데 작동하지 않습니다. 그냥 크롬 일 뿐이야? – kag359six

+0

크롬도 사용하고 있습니다. 사용중인 CSS를 볼 수 있습니까? – Thanizer

답변

관련 문제