简体   繁体   English

使用父母或兄弟姐妹的jQuery

[英]jquery using parent or siblings

Hello i have multiple galleries on one page and also using a light-box script. 您好,我在一页上有多个画廊,并且还使用灯箱脚本。 Instead of having to id each gallery differently i think i can use parent or siblings function, but i cant get it working can anyone help? 我认为不必使用不同的ID来标识每个画廊,而是可以使用父级或同级函数,但是我无法使其正常工作,有人可以帮忙吗?

<div id'gallery'>
<a id='galImage'>.....</a>
<a id='galImage'>.....</a>
<a id='galImage'>.....</a>
</div>

<div id'gallery'>
<a id='galImage'>.....</a>
<a id='galImage'>.....</a>
<a id='galImage'>.....</a>
</div>

<div id'gallery'>
<a id='galImage'>.....</a>
<a id='galImage'>.....</a>
<a id='galImage'>.....</a>
</div>

the script i'm using is 我正在使用的脚本是

$(function() {
   $('#gallery #imageGal').lightBox({
    overlayBgColor: '#FFF',
   });
});

i've tried 我试过了

$(function() {
   $("#gallery + #imageGal", this).lightBox({
    overlayBgColor: '#FFF',
   });
});

I would suggest you to use another attribute instead of ID for such purposes. 我建议您出于这种目的使用另一个属性代替ID。 For example: 例如:

<div gallery='true'>
  <a galImage='true'>.....</a>
  <a galImage='true'>.....</a>
  <a galImage='true'>.....</a>
</div>

And the script for update: 和更新脚本:

$(function() {
   $('div[gallery] a[imageGal]').lightBox({
    overlayBgColor: '#FFF',
   });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM