2013-02-15 83 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

它与其他浏览器?你得到的错误是哪一个? – nowhere 2013-02-15 08:56:51

+0

它在FF和IE中很好用。 未捕获的异常:TypeError:'o.find'不是函数 在http:// localhost:8080 /.../ jquery-1.3中的<匿名函数:find>(E)中的第12行第5629列处引发错误.2.min.js: o.find(E,this [0],F); 在http:// localhost:8080 /.../ jquery-1.3.2.min.js: return o(H)中的(E,H)的第12行,第681列调用。在http:// localhost:8080 /.../ jquery-1.3.2.min.js: 中的<匿名函数:l。$>(E,F)中查找从第12行第128列调用的(E) 返回新的o.fn.init(E,F) – AkiraYamaokaNC 2013-02-15 09:04:45

+2

@krshekhar再次;不要为此使用代码格式。 'jQuery','Opera'和'Chrome'是产品名称 - 它们不是*代码。他们不需要以*任何*方式突出显示,请。 – 2013-02-15 09:08:00

回答

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 2013-02-15 09:13:50

+0

好的排除故障,你能把脚本移动到身体的最底部吗?或者把这个脚本放在$(document).ready()中; – gaurav 2013-02-15 09:18:13

+0

当我尝试使用.ready()时,它在所有浏览器中都不起作用。 – AkiraYamaokaNC 2013-02-15 09:35:30

1

试试这个出doc readyhttp://jsfiddle.net/YRC4N/

$(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')); 
    }); 
});