如何在 IE 11 中将复选框添加到 Multi Select
How to add checkboxes to Multi Select in IE 11
我想使用 IE 11 通过 css 将复选框添加到 Multi Select。
我使用的 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 列的 table,第一列是复选框列,接下来是选项的 text/name。甚至可能是扩展的 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 中的输出:
参考:
How to use Checkbox inside Select Option
如果你想只使用 CSS 的解决方案,你也可以在上面的 link.
中找到它
我想使用 IE 11 通过 css 将复选框添加到 Multi Select。 我使用的 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 列的 table,第一列是复选框列,接下来是选项的 text/name。甚至可能是扩展的 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 中的输出:
参考:
How to use Checkbox inside Select Option
如果你想只使用 CSS 的解决方案,你也可以在上面的 link.
中找到它