国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jquery+css實現下拉列表功能

2019-11-19 15:34:28
字體:
來源:轉載
供稿:網友

廢話不多說了,直接給大家貼代碼了,具體代碼如下所述:

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>fruit</title><style type="text/css">.hide { display: none;}div { float: left; width: 100%;}.selector-containter { margin-bottom: 10px;}.selector { width: 200px; background: #FFF; border: 1px solid #DDD;}.selector-hint { width: 178px; border: 1px solid #DDD;}.selector-expand { width: 8px; border: 1px solid #DDD;}.selector-collapse { width: 8px; border: 1px solid #DDD;}</style><script src="jquery-3.2.1.min.js"></script><script>$(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');  });});</script></head><body><div id="titan" class="selector-containter"><div id="fruit"> <div class="selector">  <div class="selector-hint">select fruit</div>  <div class="selector-expand">+</div>  <div class="selector-collapse">-</div>  <div class="selector-option-container">  </div> </div></div></div><div id="athena" class="selector-t1 selector-containter"><div id="fruit"> <div class="selector">  <div class="selector-hint">select fruit</div>  <div class="selector-expand">+</div>  <div class="selector-collapse">-</div>  <div class="selector-option-container">  </div> </div></div></div></body></html>

總結

以上所述是小編給大家介紹的jquery+css實現下拉列表功能,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巨鹿县| 钦州市| 都江堰市| 绥滨县| 松阳县| 吉水县| 旬阳县| 木兰县| 渝中区| 西乌珠穆沁旗| 南平市| 平江县| 阿拉尔市| 扎兰屯市| 屏南县| 林周县| 城口县| 绥阳县| 珠海市| 花莲市| 儋州市| 牙克石市| 肥城市| 镇康县| 赤壁市| 丰原市| 庐江县| 邵阳市| 吉林省| 台东市| 永寿县| 玉溪市| 陕西省| 娄烦县| 同德县| 龙口市| 韶山市| 邹城市| 汝州市| 永福县| 专栏|