如果启用了自定义开关:
如果禁用自定义开关:
按钮可以启用自定义开关,另一个按钮可以通过JavaScript (JQuery)方法调用禁用它。
问题
似乎禁用标签的颜色不能修改。虽然对于已启用的标签也是如此。
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<style media="screen">
/* If it is enabled */
.exampleClass_label{
color: green;
font-weight: bold;
}
/* If it is disabled */
.myDiv2 .exampleClass_label{
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<h1>Hello World</h1>
<button onclick="myEnable()">Enable!</button>
<button onclick="myDisable()">Disable!</button>
<div class="custom-control custom-switch myDiv">
<input type="checkbox" class="custom-control-input"
id="exampleID_input_switch">
<label class="custom-control-label exampleClass_label"
for="exampleID_input_switch">
Title of Switch
</label>
</div>
<script type="text/javascript">
myDisable();
function myEnable() {
$(".myDiv").removeClass("myDiv2");
$('.myDiv :input').attr('disabled', false);
}
function myDisable(){
$(".myDiv").addClass("myDiv2");
$('.myDiv :input').attr('disabled', true);
}
</script>
</body>
</html>
发布于 2021-02-28 03:12:36
在添加myDiv2类时,只需设置pointer-events: none,它将充当disabled。
.myDiv2{
pointer-events: none;
}只需将上述代码放入css中即可。
https://stackoverflow.com/questions/66403943
复制相似问题