HTML
<label>
<img data-disable-checkbox="true">
<input type="checkbox" />
This checkbox value
</label>
JQuery
$("img[data-disable-checkbox='true']")
.next()
.prop("disabled", "disabled")
.css({"text-decoration":"line-through"});
我使用上面的 jquery 代码来禁用复选框和复选框文本中的线条。复选框禁用有效,但复选框文本的换行不起作用。如何到达复选框文本并插入一条线?
最佳答案
代码尝试将 text-decoration
属性添加到复选框,而不是 label
。找到 label
类型的元素的父级并应用样式。
$("img[data-disable-checkbox='true']").next().prop("disabled", "disabled");
$("img[data-disable-checkbox='true']").parent("label")
.css({"text-decoration":"line-through"});
关于jquery - 在输入类型复选框中设置文本样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17805180/