新聞中心
這篇文章主要為大家展示了“如何使用jQuery實(shí)現(xiàn)可輸入多選下拉組合框”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“如何使用jQuery實(shí)現(xiàn)可輸入多選下拉組合框”這篇文章吧。
基于這種原因,于是私下用jquery寫了一個(gè)比較簡(jiǎn)單的多選下拉可填寫組合框?! ?/p>
container{ margin: 20px auto; padding:0 15px; width: 50%; height:300px; box-sizing: border-box; } .text-container{ display: inline-block; float:left; width: 15%; height: 32px; line-height: 32px; box-sizing: border-box; } .selectContainer{ width: 70%; height:200px; float:left; position: relative; padding:0; margin:0; box-sizing: border-box; } .selectedContent{ width:85%; height: 25px; float:left; } .dropDown-toggle{ width:14%; height:31px; line-height: 31px; text-align: center; border: 1px solid silver; border-left:none; float:left; padding:0; margin:0; box-sizing: border-box; cursor: pointer; } .dropDown-menu{ margin:0; padding:0 15px 10px; width:100%; border:1px solid silver; border-top: none; box-sizing: border-box; list-style: none; position: absolute; top:31px; right:0; } .items{ margin-top:8px; padding: 2px; cursor: pointer; } .items:hover{ background: #ddd; } .isSelectedText{ display: inline-block; width:90%; } .dsn{ display: none; }
最愛的水果選擇
- 蘋果
- 梨
- 橘子
$('.isSelected input[type=checkbox]').on('click', function(){ var selectedItems = $(this).parents('.dropDown-menu').prevAll('.selectedContent').val().split(' '); var thisItem = $(this).parent().prev().text(); var isExisted = 0; var isChecked = $(this).is(':checked'); if(isChecked){ selectedItems.map(function(item, index){ if(item === thisItem){ isExisted++ } }); if(!isExisted){ selectedItems.push(thisItem) } } else{ selectedItems.map(function(item, index){ if(item === thisItem){ selectedItems.splice(index, 1); } }); } $(this).parents('.dropDown-menu').prevAll('.selectedContent').val(selectedItems.join(' ')); }) $('.confirmSelect').on('click', function(){ $(this).parents('.dropDown-menu').addClass('dsn'); }) $('.dropDown-toggle').on('click', function(){ $(this).next().toggleClass('dsn') });
由于本組件中使用了數(shù)組的map方法,可能此方法在ie中不能兼容。由于我電腦ie無法打開,用360瀏覽器測(cè)試后同樣可是正常使用。
以上是“如何使用jQuery實(shí)現(xiàn)可輸入多選下拉組合框”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司行業(yè)資訊頻道!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.cdcxhl.com,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
本文名稱:如何使用jQuery實(shí)現(xiàn)可輸入多選下拉組合框-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)URL:http://www.dlmjj.cn/article/coeppj.html