html - 如何设置复选框内容?
问题描述
在我的角度应用程序中。我正在使用复选框。我从 API 获取数据。如果复选框的值为真。输入值的内容显示一个勾号。如果值为 false 而不是空复选框,我如何在复选框中显示“X”。请指导我。
HTML
<input class="input" [ngclass]="testForm.get('test').value === false?'unchecked':none " type="checkbox" formControlName="test" readonly>
css
.unchecked {
content: 'X';
color: #fff;
}
解决方案
演示 您可以为此使用 css
<div>
<input class="input" id="checkbox-1"class="checkbox-custom" type="checkbox" readonly>
<label for="checkbox-1" class="checkbox-custom-label">First Choice</label>
</div>
作为CSS
.checkbox-custom:checked + .checkbox-custom-label:before {
content: "\f00c";
font-family: 'FontAwesome';
background: blue;
color: #fff;
}
#checkbox-1{
opacity: 0;
position: absolute;
}
.checkbox-custom + .checkbox-custom-label:before, .radio-custom + .radio-custom-label:before {
display: inline-block;
vertical-align: middle;
width: 14px;
height: 14px;
padding: 3px;
text-align: center;
content: "\f00d";
font-family: 'FontAwesome';
background: red;
color:white;
}
推荐阅读
- c - 在流水线图中,数据危害的数据转发如何工作
- nestjs - 布尔查询参数被视为字符串,而不是转换为布尔数据类型
- javascript - 加快 Gatsby 性能
- geojson - 如何使用 GeoTools gt-geojsondatastore 插件读取包含单个功能的 GeoJSON 文件?
- wordpress - 如何在 woocommerce 中获取 wp_woocommerce_session_ 值?
- android - Android 将最新的 AOSP 提交到我的项目中
- linux - 如何同时在多个主机上运行远程脚本
- tree - 在图中,两个顶点之间的最短路径怎么可能比图的最小生成树中这两个顶点之间的路径长?
- python - 如果 FTP-Server 中的新文件运行程序
- c# - 在 Acumatica 中确认发货时如何旋转从承运人检索到的发货标签图像?