我想在不影响嵌套的<input>
标签的情况下禁用或隐藏<label>
标签的内容“分组”。
<label class="" for="officersheet_fields_attributes_3_grouping">
<input type="checkbox" id="officersheet_fields_attributes_3_grouping" name="officersheet[fields_attributes][3][grouping]" value="1">
Grouping
</label>`
我在rails中使用了formtastic。形式化代码片段<td><%= f.input :grouping %></td>
上面的代码行生成了上面的html。
提前感谢
发布于 2013-03-12 17:14:01
您可以使用text-indent: -1000em
。
label
{
text-indent: -1000em;
}
但我不认为将输入放在标签中是个好主意。最好有以下内容:
<input type="checkbox"/><label>Grouping</label>
发布于 2013-03-12 17:18:45
在标签文本周围添加span
标签并将其隐藏
<label for="foo">
<input type="checkbox" value="1"><span>Grouping</span>
</label>
CSS
span{
display:none
}
发布于 2013-03-12 17:37:28
我也会选择跨度,但是如果你无法控制你的html结构,你可以这样做:
$(document).ready(function () {
$('label')
.contents()
.each(function() {
// if (this.nodeType == Node.TEXT_NODE); this works unless using IE 7
if (this.nodeType === 3) {
$(this).remove();
}
});
});
https://stackoverflow.com/questions/15357198
复制相似问题