gpt4 book ai didi

javascript - 自定义下拉列表不起作用

转载 作者:行者123 更新时间:2023-11-30 12:40:08 24 4
gpt4 key购买 nike

我正在尝试创建一个自定义下拉列表。我想在我的下拉列表中有两个选项,即预定义和自定义。当我从列表中选择自定义时,它没有被选中。到目前为止,我有这段代码无法正常工作。

    <html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
function DropDown(el) {
this.dd = el;
this.initEvents();
}
DropDown.prototype = {
initEvents : function() {
var obj = this;

obj.dd.on('click', function(event){
$(this).toggleClass('active');
event.stopPropagation();
});
}
}
$(function() {

var dd = new DropDown( $('#dd') );

$(document).click(function() {
// all dropdowns
$('.wrapper-dropdown-5').removeClass('active');
});

});

</script>
<style>
.wrapper-dropdown-5 {
/* Size & position */
position: relative;
width: 144px;
margin: 0 auto;
padding: 12px 15px;

/* Styles */
background: #fff;
cursor: pointer;
outline: none;
transition: all 0.3s ease-out;
}
.wrapper-dropdown-5:after { /* Little arrow */
content: "";
width: 0;
height: 0;
position: absolute;
top: 50%;
left: 165px;
margin-top: -3px;
border-width: 6px 6px 0 6px;
border-style: solid;
border-color: #067ab4 transparent;
}
.wrapper-dropdown-5 .dropdown {
/* Size & position */
position: absolute;
top: 30%;
left: -40;
right: 0;

/* Styles */

list-style: none;
transition: all 0.3s ease-out;

/* Hiding */
max-height: 0;
overflow: hidden;
}
.wrapper-dropdown-5 .dropdown li {
padding: 0 10px ;
}
.wrapper-dropdown-5 .dropdown li a {
display: block;
text-decoration: none;
color: #067ab4;
transition: all 0.3s ease-out;

}
.wrapper-dropdown-5 .dropdown li:last-of-type a {
border: none;
}
.wrapper-dropdown-5 .dropdown li i {
margin-right: 5px;
color: inherit;
vertical-align: middle;
}
/* Hover state */
.wrapper-dropdown-5 .dropdown li:hover a {
color: #57a9d9;
}
/* Active state */
.wrapper-dropdown-5.active {
border-radius: 5px 5px 0 0;
box-shadow: none;
border-bottom: none;
color: white;
}
.wrapper-dropdown-5.active:after {
border-color: #067ab4 transparent;
}
.wrapper-dropdown-5.active .dropdown {
border-bottom: 0px solid rgba(0,0,0,0.2);
max-height: 400px;
}
div#dd
{
color: #067ab4;
font: 30px tahoma;
display: inline-block;
}
div#textA
{
display: inline-block;
font: 30px tahoma;
padding-left: 20px;
}
div#textB
{
display: inline-block;
font: 30px tahoma;
padding-left: 6px;
}
</style>
</head>
<body> <div id="textA">I want to select a</div>
<div id="dd" class="wrapper-dropdown-5" tabindex="1">Predefined
<ul class="dropdown">
<li><a href="#"><i class="icon-user"></i>Custom</a></li>
</ul>
</div>
<div id="textB">profile</div>
</body>
<html>

最佳答案

您必须将一个事件监听器附加到导航项才能使其工作,否则您已经编写了所有这些 javascript 并且没有任何调用它来工作。

Event Listeners

关于javascript - 自定义下拉列表不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24791074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com