0

CDN を使用するようにサイトをセットアップしましたが、これはすべて計画どおりに進んでおり、画像に使用しているカラーボックスを除いて、ほとんどが意図したとおりに機能します。

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コードを書き直して機能させるのを手伝ってくれる人はいますか? ありがとうございました。

4

3 に答える 3

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

ただし、可能であれば、画像にクラスを追加して、画像を簡単に選択できるようにすることができます。

于 2012-09-10T16:30:46.277 に答える
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%'
});
于 2012-09-10T16:28:42.610 に答える
0

または、 Contains Wordの代わりに、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%'
});

それは私のために働いています

于 2012-09-10T16:31:58.920 に答える