【问题标题】:Apending variable in Jquery selector在 Jquery 选择器中附加变量
【发布时间】:2017-08-15 22:16:59
【问题描述】:

我有这个选择器

self = $('.trim .person:nth-child('+index+')');
self.append('<img src="'+element.profilePic+'" class="profilePic" />');

然后我想用这个在

中选择一个类
  $(self + '.spacer').css('opacity', 0.5);

我也试过

self + $('.spacer').css('opacity', 0.5);

【问题讨论】:

    标签: jquery variables jquery-selectors


    【解决方案1】:

    将其设置为context parameter in jQuery。

    $('.spacer', self).css('opacity', 0.5);
    

    或者使用find()方法获取当前jQuery对象中的元素。

    self.find('.spacer').css('opacity', 0.5);
    

    【讨论】:

      猜你喜欢
      • 2014-03-15
      • 1970-01-01
      • 2020-08-03
      • 1970-01-01
      • 2011-05-06
      • 1970-01-01
      • 2013-07-03
      • 1970-01-01
      • 2010-12-23
      相关资源
      最近更新 更多