2012-11-18 233 views

回答

5

我假設你有一個選擇器,用於匹配href屬性值/的元素。你需要把/字符報價:

var elems = $("[href='/']"); 

或者,你能逃脫字符:

var elems = $("[href=\\/]"); 

jQuery docs

If you wish to use any of the meta-characters (such as !"#$%&'()*+,./:;<=>[email protected][\]^ {|}~`) as a literal part of a name, you must escape the character with two backslashes: \\.

這裏有一個working example。刪除引號以生成您在問題中提到的相同錯誤。

+0

我會仔細看看它。但這很奇怪,因爲我在這個網站上有很多其他的腳本,並且從來沒有這個錯誤。它剛剛添加JQuery Tools後就出現了。我甚至不使用它,只是加載。 – camcam

+0

我上面的評論是錯誤的。刪除JQuery工具後,現在在JQuery本身發生錯誤。所以我之前沒有注意到它。 – camcam

+0

一切都很清楚。這實際上是我在這個網站上使用的其他腳本中的一個錯誤,並且正是使用href =/without quotes。謝謝你的提示。 (我的錯,我沒有看到Chrome中的這個錯誤的調用堆棧,它會更快找到) – camcam

0

我的猜測是你改變了庫的順序。如果你想使用JQuery,它的lib必須先被加載才能使用額外的JQuery擴展庫。您應該更改<head>中的順序,如下所示:

<html> 
<head> 
    <link rel="stylesheet" type="text/css" href="formate.css"> //CSS always first 
    <script src="URL_TO_JQUERY" type="text/javascript"></script> //JQuery first 
    <script src="URL_TO_ADDITIONAL_LIB_1" type="text/javascript"></script> 
    <script src="URL_TO_ADDITIONAL_LIB_..." type="text/javascript"></script> 
    <script src="URL_TO_ADDITIONAL_LIB_n" type="text/javascript"></script> 
</head> 
</html> 
相關問題