html下拉菜单jq怎么设置,jquery+css实现下拉列表功能

本文详细介绍了如何使用jQuery和CSS创建一个可动态扩展的下拉列表,包括点击展开与折叠选项、切换选中项提示及取消选中功能。适合前端开发者学习和参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

废话不多说了,直接给大家贴代码了,具体代码如下所述:

fruit

.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;

}

$(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('

apricot
');

$(this).parent().children('.selector-option-container').append('

banana
');

$(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实现下拉列表功能,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值