gpt4 book ai didi

javascript - 拆分按钮不工作

转载 作者:太空宇宙 更新时间:2023-11-04 01:53:29 25 4
gpt4 key购买 nike

我在我的应用程序中使用这个示例。 https://codepen.io/kushalpandya/pen/IAhin/按钮完美地出现在屏幕上。我放置div相应地部分和所有CSS。现在当我点击箭头按钮时不知道为什么选项没有显示。我的拆分按钮不起作用。

$(function() {
var splitBtn = $('.x-split-button');

$('button.x-button-drop').on('click', function() {
if (!splitBtn.hasClass('open'))
splitBtn.addClass('open');
});

$('.x-split-button').click(function(event) {
event.stopPropagation();
});

$('html').on('click', function() {
if (splitBtn.hasClass('open'))
splitBtn.removeClass('open');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="containerButton">
<span class="x-split-button">
<button class="x-button x-button-main">&#10070; Action</button>
<button class="x-button x-button-drop">&#9660;</button>
<ul class="x-button-drop-menu">
<li>
<a href="#">Item - 1</a>
</li>
<li>
<a href="">Item - 2</a>
</li>
<li>
<a href="">Long Item - 3</a>
</li>
</ul>
</span>
</div>

我有没有放<Script>正确标记。

最佳答案

还需要添加css!检查这个:

$(function() {
var splitBtn = $('.x-split-button');

$('button.x-button-drop').on('click', function() {
if (!splitBtn.hasClass('open'))
splitBtn.addClass('open');
});

$('.x-split-button').click(function(event) {
event.stopPropagation();
});

$('html').on('click', function() {
if (splitBtn.hasClass('open'))
splitBtn.removeClass('open');
});
});
.container {
text-align: center;
}

.container > h2 {
text-align: center;
}

.x-split-button {
position: relative;
display: inline-block;
text-align: left;
margin-top: 20px;
}

.x-button {
position: relative;
margin: 0;
height: 30px;
float: left;
outline: none;
line-height: 27px;
background: #F2F2F2;
border: 1px solid #E0E0E0;
box-shadow: 1px 1px 2px #E0E0E0;
}

.x-button:hover {
cursor: pointer;
background: #E0E0E0;
}

.x-button:active {
background: #D3D3D3;
}

.x-button.x-button-drop {
border-left: 0;
height: 30px;
}

.open > .x-button-drop-menu {
display: block;
}

.x-button-drop-menu {
position: absolute;
top: 27px;
right: 0;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
padding: 5px 0;
margin: 2px 0 0;
font-size: 14px;
list-style: none;
background-color: #F2F2F2;
background-clip: padding-box;
border: 1px solid #E0E0E0;
box-shadow: 1px 1px 2px #E0E0E0;
}

.x-button-drop-menu li a {
display: block;
padding: 3px 20px;
clear: both;
font-family: arial;
color: #444;
text-decoration: none;
}

.x-button-drop-menu li a:hover {
background: #D3D3D3;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="containerButton">
<span class="x-split-button">
<button class="x-button x-button-main">&#10070; Action</button>
<button class="x-button x-button-drop">&#9660;</button>
<ul class="x-button-drop-menu">
<li>
<a href="#">Item - 1</a>
</li>
<li>
<a href="">Item - 2</a>
</li>
<li>
<a href="">Long Item - 3</a>
</li>
</ul>
</span>
</div>

关于javascript - 拆分按钮不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43040454/

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