【发布时间】:2020-06-19 15:01:30
【问题描述】:
我想根据复选框的状态更改标签的值
function private() {
var checkBox = document.getElementById("private");// Get the checkbox
var text = document.querySelector('label[for="private"]');// Get the output text
if (checkBox.checked == true)
{
text.innerHTML = "Public";
} else {
text.innerHTML = "Private";
}
}
<label class="switch">
<input id="private" type="checkbox" onclick="private()" />
<span class="slider"></span>
</label>
<label for="private"></label>
为什么这不起作用?
【问题讨论】:
-
@HereticMonkey 它有帮助,但它无论如何都不起作用
标签: javascript html function innerhtml