Jquery和CSS实现选择框重置按钮功能
很多时候我们都会用到一个下拉选择,还有就是重置的功能,今天我们就给大家带来用Jquery配合CSS实现的这个功能。
代码如下:
HTML
<select> <option value="">Select a color..</option> <option value="red">Red</option> <option value="green">Green</option> <option value="blue">Blue</option> </select> <div class="displaySelect"> <span class="value"></span> <span class="close">⊗</span> </div>
CSS
.displaySelect{ display:none; border: 1px solid; } select, .displaySelect { text-indent:20px; font-family:helvetica; } select, .displaySelect{ font-size:22px; height:50px; line-height:50px; width:100%; text-transform:capitalize; } .displaySelect .close{ display:block; float:right; width:10%; text-align:center; font-size:52px; cursor:pointer; }
Jquery
var select = $('select'); var selectResults = $('.displaySelect'); var selectValue = $('.value', selectResults); var selectClose = $('.close', selectResults); select.on('change', function() { $(this).add(selectResults).toggle(); selectValue.html(this.value); }); selectClose.click(function(){ select.val('').fadeIn(); selectResults.toggle(); selectValue.html(''); });
效果如下:
相关推荐
专注前端开发 2020-10-21
苏康申 2020-11-13
vitasfly 2020-11-12
oraclemch 2020-11-06
liuyang000 2020-09-25
FellowYourHeart 2020-10-05
赵继业 2020-08-17
whyname 2020-08-16
Seandba 2020-08-16
dbasunny 2020-08-16
拼命工作好好玩 2020-08-15
langyue 2020-08-15
写程序的赵童鞋 2020-08-03
Accpcjg 2020-08-02
tydldd 2020-07-30
好记忆也需烂 2020-07-28
jianghero 2020-07-28