<span class="switchery switchery-small" style="box-shadow: rgb(223, 223, 223) 0px 0px 0px 0px inset; border-color: rgb(223, 223, 223); transition: border 0.4s, box-shadow 0.4s; background-color: rgb(255, 255, 255);">
<small style="left: 0px; transition: background-color 0.4s, left 0.2s;"></small>
</span>
我正在使用一个插件,它生成了上面的代码。如何选择其左侧为0px的小标签的交换器?
我写了这个
if ($('.switchery').find('small').attr('style').indexOf('0px') > -1) {
}
但是如何应用click()
我的matchs元素。
将过滤器与回调一起使用。
<small>
元素中的所有.switchery
元素left
属性为零的元素var smallEl = $('.switchery small').filter(function() {
return parseInt($(this).css('left')) === 0;
}).css('color', 'green');
smallEl.click(function() {
console.log('Hello');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<span class="switchery switchery-small" style="box-shadow: rgb(223, 223, 223) 0px 0px 0px 0px inset; border-color: rgb(223, 223, 223); transition: border 0.4s, box-shadow 0.4s; background-color: rgb(255, 255, 255);">
<small style="left: 0px; transition: background-color 0.4s, left 0.2s;">Left 0</small>
<small style="left: 100px; transition: background-color 0.4s, left 0.2s;">Left 100</small>
<small style="transition: background-color 0.4s, left 0.2s;">No Left</small>
</span>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句