jquery下统一class名来无效上下小图标

现在一个页面有2个部分的上下无效图标判断,这里的意思是要把它封装一下。
全部把class定义上item-up,item-down。
可是却发现,这个只有第一个最上面的图标无效,和第二个最下面的图标无效。
无法做到分别在各自的那一块无效。
只有class不一样才能分别最上面和最下面无效。
现在想在html的class上统一定义就是,item-up,item-down。但是不知道jquery这边怎么写怎么判断啊,如果以后页面是三块,四块呢?
总之在class类名不变的情况下,想封装。

现在的html视图如下

1图标上<button type="button"  class="btn btn-primary btn-xs angle-up item-up-1"><i class="fa fa-angle-up" aria-hidden="true"></i></button> 
1图标下<button type="button"  class="btn btn-primary btn-xs angle-down item-down-1"><i class="fa fa-angle-down" aria-hidden="true"></i></button>

2图标上<button type="button"  class="btn btn-primary btn-xs angle-up item-up-2"><i class="fa fa-angle-up" aria-hidden="true"></i></button> 
2图标下<button type="button"  class="btn btn-primary btn-xs angle-down item-down-2"><i class="fa fa-angle-down" aria-hidden="true"></i></button>

想把class全部统一成

class="btn btn-primary btn-xs angle-up item-up"
class="btn btn-primary btn-xs angle-up item-down"

现在的jq如下 不知道怎么写

$(document).ready(function(){
    $(".item-up").eq(0).prop("disabled", true);
    $(".item-down").eq(-1).prop("disabled", true);  
  
});
阅读 1.8k
1 个回答

经过一番拉锯,最终的效果是这样的:http://jsfiddle.net/djyuning/...
其实就是 选择器遍历 的用法!

$(function() {
  $.each($('.content'), function(index, section) {
    var $section = $(section);
    // 全部消除禁用
    $section.find('.btn').prop('disabled', false);
    // 第一个子级的 up 按钮禁用
    $section.find('table tbody tr').first().find('.item-up').prop('disabled', true);
    // 最后一个子级的 down 按钮禁用
    $section.find('table tbody tr').last().find('.item-down').prop('disabled', true);
  });
});
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题