gpt4 book ai didi

css - 如何在 IE 11 中为多选添加复选框

转载 作者:行者123 更新时间:2023-11-28 00:21:00 25 4
gpt4 key购买 nike

我想使用 IE 11 通过 css 将复选框添加到多选。我使用的 css 适用于 Edge 等,但不适用于 IE 11。

CSS 和代码:

<style>
option:before
{
content: "☐ "
}

option:checked:before
{
content: "☑ "
}

<select class="ddlRole" id="ddlRole" style="width: 810px;" size="6" multiple="">
<option value="1">Administrator</option>
<option selected="selected" value="2">Manager</option>
<option value="3">User</option>
<option selected="selected" value="4">Sub Manager</option>
<option value="8">new role test 5</option>
</select>

或者,我将使用一个包含 2 列的表格,第一列是复选框列,接下来是选项的文本/名称。甚至可能是扩展的 Ul 和 Li?,虽然我真的不愿意。

谢谢

最佳答案

如果您尝试使用 HTML、CSS 和 JS,那么下面的示例可以在包括 IE 在内的所有主流浏览器上运行。

var expanded = false;

function showCheckboxes() {
var checkboxes = document.getElementById("checkboxes");
if (!expanded) {
checkboxes.style.display = "block";
expanded = true;
} else {
checkboxes.style.display = "none";
expanded = false;
}
}
.multiselect {
width: 200px;
}

.selectBox {
position: relative;
}

.selectBox select {
width: 100%;
font-weight: bold;
}

.overSelect {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}

#checkboxes {
display: none;
border: 1px #dadada solid;
}

#checkboxes label {
display: block;
}

#checkboxes label:hover {
background-color: #1e90ff;
}
<form>
<div class="multiselect">
<div class="selectBox" onclick="showCheckboxes()">
<select>
<option>Select an option</option>
</select>
<div class="overSelect"></div>
</div>
<div id="checkboxes">
<label for="one">
<input type="checkbox" id="one" />First checkbox</label>
<label for="two">
<input type="checkbox" id="two" />Second checkbox</label>
<label for="three">
<input type="checkbox" id="three" />Third checkbox</label>
</div>
</div>
</form>

IE 11 中的输出:

enter image description here

引用:

How to use Checkbox inside Select Option

如果你想要一个只使用 CSS 的解决方案,你也可以在上面的链接中找到它。

other example with JQuery:

关于css - 如何在 IE 11 中为多选添加复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54870036/

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