gpt4 book ai didi

javascript - 用文字制作三态切换

转载 作者:行者123 更新时间:2023-11-28 14:09:06 24 4
gpt4 key购买 nike

enter image description here

$(document).ready(function() {
$('input[type="checkbox"]').click(function() {
$('input[type="checkbox"]').not(this).prop("checked", false);
var inputValue = $(this).attr("value");
$("." + inputValue).toggle().siblings(".box").hide()
});
});
.box {
color: #fff;
padding: 20px;
display: none;
margin-top: 20px;
}

.red {
background: #ff0000;
display: none
}

.green {
background: #228B22;
display: none
}

.blue {
background: #0000ff;
display: block;
}

.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}

.switch input {
opacity: 0;
width: 0;
height: 0;
}

.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}

.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}

input:checked+.slider {
background-color: #2196F3;
}

input:focus+.slider {
box-shadow: 0 0 1px #2196F3;
}

input:checked+.slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}

.slider.round {
border-radius: 34px;
}

.slider.round:before {
border-radius: 50%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<label class="switch">
<input type="checkbox" name="colorCheckbox" value="blue" checked>
<span class="slider round"></span>
</label>
<label class="switch">
<input type="checkbox" name="colorCheckbox" value="green">
<span class="slider round"></span>
</label>
<label class="switch">
<input type="checkbox" name="colorCheckbox" value="red">
<span class="slider round"></span>
</label>
</div>

<div class="red box">You have selected <strong>red checkbox</strong> so i am here</div>
<div class="green box">You have selected <strong>green checkbox</strong> so i am here</div>
<div class="blue box">You have selected <strong>blue checkbox</strong> so i am here</div>

我目前有三个开关,但我想要三个状态开关,类似这样--- /image/EH2MN.png ------但有文字

此代码具有三个差异开关,默认情况下选择第一个。被选中的那个给出被选中的特定一个的文本。

这里我添加代码片段以便更好地理解,以便清楚地理解

最佳答案

您正在寻找的不是切换按钮,而是单选按钮类型的输入。提供了答案in this question它使用 3 个 radio 输入和一些样式来实现我相信您正在寻找的东西。

.radio-toolbar input[type="radio"] {
display: none;
}

.radio-toolbar label {
display: inline-block;
background-color: #ddd;
padding: 4px 11px;
font-family: Arial;
font-size: 16px;
cursor: pointer;
}

.radio-toolbar input[type="radio"]:checked+label {
background-color: #bbb;
}
<div class="radio-toolbar">
<input type="radio" id="radio1" name="radios" value="all" checked>
<label for="radio1">All</label>

<input type="radio" id="radio2" name="radios" value="false">
<label for="radio2">Open</label>

<input type="radio" id="radio3" name="radios" value="true">
<label for="radio3">Archived</label>
</div>

关于javascript - 用文字制作三态切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56789833/

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