2012-09-10 13 views
0

我剛剛設置我的網站以使用CDN,它已全部按計劃進行,並且大多按預期工作 - 除了colorbox之外, m用於圖像。ColorBox - 用於CDN上所有圖像的jQuery選擇器

我有一種感覺,它不再工作,因爲所有的圖像對他們(如image.png?9d7bd4)的最後一個查詢字符串,它打破了我的jQuery選擇:

/* colorbox - use it on all links to images */ 
$('a[href$=".jpg"],a[href$=".jpeg"],a[href$=".png"],a[href$=".gif"]').colorbox({ 
    'rel': 'images', 
    'photo': true, 
    'maxWidth': '90%', 
    'maxHeight': '90%' 
}); 

燦有人幫我重寫jQuery代碼以使其工作?謝謝。

回答

2

什麼你使用的是與選擇的兩端。您想要將其更改爲「包含」。

/* colorbox - use it on all links to images */ 
$('a[href*=".jpg"],a[href*=".jpeg"],a[href*=".png"],a[href*=".gif"]').colorbox({ 
    'rel': 'images', 
    'photo': true, 
    'maxWidth': '90%', 
    'maxHeight': '90%' 
}); 

在屬性選擇更多信息:https://developer.mozilla.org/en-US/docs/CSS/Attribute_selectors

但如果可能的話,你可以一類添加到圖像,使他們選擇更容易。

+0

@ davethegrt8 - 絕對的,如果允許CLASS,對於前期維護來說要好得多。 –

+0

完美的作品,謝謝。我可以/應該只是使用類選擇器,但我有點想要更容易使用的東西(即不需要我爲每個鏈接的圖像手動分配一個類)。 –

0

除了使用的末端,與選擇,你可以使用contains

/* colorbox - use it on all links to images */ 
$('a[href*=".jpg"],a[href*=".jpeg"],a[href*=".png"],a[href*=".gif"]').colorbox({ 
    'rel': 'images', 
    'photo': true, 
    'maxWidth': '90%', 
    'maxHeight': '90%' 
}); 
+0

僅供參考,〜=比* =所以這可能會導致意想不到的結果略有不同。 – davethegr8

+0

@ davethegr8 - 你說得對,我打算做星號選擇器。我編輯了我的帖子。謝謝。 –

+0

完美的作品,謝謝。 –

0

或替代包含文字可以使用包含選擇

/* colorbox - use it on all links to images */ 
$('a[href*=".jpg"],a[href*=".jpeg"],a[href*=".png"],a[href*=".gif"]').colorbox({ 
    'rel': 'images', 
    'photo': true, 
    'maxWidth': '90%', 
    'maxHeight': '90%' 
}); 

它的工作對我來說

+0

完美的作品,謝謝。 –