2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > html下拉菜单jq怎么设置 jquery+css实现下拉列表功能

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

时间:2020-05-28 12:35:18

相关推荐

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

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

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。