jquery+css 드롭다운 목록 기능 구현

3121 단어
잔말 말고 바로 코드를 붙여드리겠습니다. 구체적인 코드는 다음과 같습니다.





fruit



$(document).ready(function() {
  //  on  ,        ,selector-option-container           
  $('.selector').on('click', '.selector-expand', function() {
    $(this).parent().children('.selector-option-container').children().remove();
    $(this).parent().children('.selector-option-container').append('<div><input type="checkbox" name="fruitGroup" class="selector-checkbox"/></div><div class="selector-option">apricot</div>');
    $(this).parent().children('.selector-option-container').append('<div><input type="checkbox" name="fruitGroup" class="selector-checkbox"/></div><div class="selector-option">banana</div>');
    $(this).nextAll('.selector-option-container').removeClass('hide');
  });
  $('.selector').on('click', '.selector-collapse', function() {
    $(this).nextAll('.selector-option-container').addClass('hide');
  });
  $('.selector-t1').on('click', '.selector-option', function() {
    $(this).parent().parent().children('.selector-hint').text($(this).text());
    $(this).parent().addClass('hide');
  });
  $('.selector-t1').on('click', '.selector-checkbox', function() {
    $(this).parent().parent().parent().children('.selector-hint').text($(this).parent().next().text());
    //  prop  ,            
    $(this).prop('checked', false);
    $(this).parent().parent().addClass('hide');
  });
});



select fruit
+
-
select fruit
+
-

총결산
위에서 말한 것은 편집자가 여러분에게 소개한 jquery+css가 아래 목록 기능을 실현하는 것입니다. 여러분에게 도움이 되었으면 합니다. 만약에 궁금한 것이 있으면 저에게 댓글을 남겨주시면 편집자는 제때에 여러분께 답장을 드리겠습니다!

좋은 웹페이지 즐겨찾기