2013-02-15 3 views
1

jquery가 Opera와 Chrome에서 작동하지 않는 이유는 무엇입니까?jQuery 동적 CSS 변경

<script language="JavaScript"> 
    $('link[href="includes/styles.css"]').attr("href", "includes/new_styles.css"); 
    $('link[href="includes/jmesa/jmesa.css"]').attr("href", "includes/jmesa/new_jmesa.css"); 
</script> 
+2

http://jsfiddle.net/YRC4N/가 다른 브라우저와 함께 작동합니까? 어느 오류가 발생 했습니까? – nowhere

+0

그것은 FF와 IE에서 잘 작동합니다. 잡히지 않는 예외 : TypeError : 'o.find'가 함수가 아닙니다. http : // localhost : 8080 /.../ jquery-1.3에서 <익명 함수 : 찾기> (E)의 12 행 5629 열에 오류가 발생했습니다. .2.min.js : o.find (E, this [0], F); 은 http : // localhost : 8080 /.../ jquery-1.3.2.min.js : return o (H)의 <익명 함수 : init> (E, H)에서 12 행 681 열에서 호출되었습니다. (익명 함수 : l. $> (E, F) : http : // localhost : 8080 /.../ jquery-1.3.2.min.js : 의 12 행 128 열에서 호출 된 을 찾습니다. 새로운 o.fn.init를 반환하십시오 (E, F) – AkiraYamaokaNC

+2

@krshekhar 다시; 이를 위해 코드 형식을 사용하지 마십시오. 'jQuery', 'Opera'및 'Chrome'은 제품 이름이며 * 코드 *가 아닙니다. * 어떤 방식 으로든 강조 표시 할 필요는 없습니다. –

답변

0

시도 :

<script language="JavaScript"> 
$('link[href*="includes/styles.css"]').attr("href", "includes/new_styles.css"); 
$('link[href*="includes/jmesa/jmesa.css"]').attr("href", "includes/jmesa/new_jmesa.css"); 
</script> 
+0

그건 도움이되지 못했습니다. – AkiraYamaokaNC

+0

그래, 더 많은 문제를 해결하면 스크립트를 본문의 가장 아래쪽 끝으로 옮길 수 있습니까? 또는이 스크립트를 $ (document) .ready(); – gaurav

+0

.ready()를 사용하려고하면 모든 브라우저에서 작동하지 않습니다. – AkiraYamaokaNC

1

doc ready이 밖으로 시도 :

$(function(){ 
    $('link[href$="styles.css"]').attr("href", "includes/new_styles.css"); 
    $('link[href$="jmesa.css"]').attr("href", "includes/jmesa/new_jmesa.css"); 

    $('link').each(function() { 
     console.log($(this).attr('href')); 
    }); 
});