1

http://tympanus.net/codrops/2010/10/07/slider-gallery/の写真スライダーコードを使用して、画像の下のリンクが新しいウィンドウに読み込まれるように変更しようとしています。

例えば:

<div class="content">
<div><a href="#"><img src="http://imageurl" alt="largeimageurl" /></a></div>
<div class="caption"><a target="_blank" href="image.php?id=someid&svc=somesvc" rel="nofollow">More Info</a></div>
</div>

私はjavascriptファイルでさまざまなことを試しました。現在は次のようになっています。

$fp_content_wrapper.find('.content').bind('click',function(e){
    var $current = $(this);
    //track the current one
    current = $current.index();
    //center and show this image
    //the second parameter set to true means we want to
    //display the picture after the image is centered on the screen
    centerImage($current,true,600);
    e.preventDefault();
    });

私がする必要があるのは、その最初の行を変更して、通常どおりに選択するようにしますが、リンクが含まれているキャプションdivには何も適用しないため、通常どおりに動作します。

SOについても同様の質問があることは知っていますが、提案された質問のほとんどを試しました。私はJSの経験がまったくないので、簡単に間違っている可能性があります。

助けに感謝します!

4

3 に答える 3

2

これを試して:

$fp_content_wrapper.find('.content>*:not(.caption)').bind('click',function(e) .....

何が起こっていたのかというと、コンテンツタグを選択していたのですが、代わりに、.csptionクラスを持つものを除いて、コンテンツタグ内にあるものを選択したかったのです。「>」はすぐ下の要素を意味し、「*」はすべてを選択することを意味します。つまり、「。captionのクラスではない.contentのすぐ下にあるものをすべて選択する」ということです。

jqueryを使い続ける場合は、セレクターを調べてみる価値があります。

幸運を

于 2012-04-30T12:14:29.363 に答える
1

試す:

$fp_content_wrapper.find('.content:not(.caption)').bind("click", ...
于 2012-04-30T10:11:43.947 に答える
0

このジェームスを試してみてください

$fp_content_wrapper.find('.content').bind('click',function(e){     
   if(!$(this).attr('class'))   
   {
     var $current = $(this);     
     //track the current one     
     current = $current.index();     
     //center and show this image     
     //the second parameter set to true means we want to     
     //display the picture after the image is centered on the screen     
     centerImage($current,true,600);     
     e.preventDefault();  
   }
}); 

これを行うためのより良い方法がありますが、これは行う必要があります。これにより、クラスを持たないdivのみが関数を実行するようになります。他のdivでクラスを使用する場合は、明らかに注意するか、ロジックを変更してください。

乾杯

編集:

コードをもう一度調べた後、div内のハイパーリンクをテストして、alt属性があるかどうか、または属性が何であるかを確認することもできaltます。これは、より具体的なテストになります。

于 2012-04-30T10:42:41.543 に答える