我有一个单选复选框用于切换:
<label><input type="checkbox" name="myfield" id="myfield" /> Sound On</label>
用户可以点击它以启用网站上的声音。我想取消选中复选框,单击一个href链接。
有什么想法吗?
答案 0 :(得分:1)
您需要将一个事件侦听器附加到该链接,只要单击该链接,就会收到通知。在事件监听器中,您只需取消选中该复选框。
<html>
<body>
<input type="checkbox" name="myfield" id="myfield" />
<label>Sound On</label>
<a id="myhref">uncheck</a>
<script>
// Get a reference to "myhref".
var myhref = document.getElementById("myhref");
// Get a reference to "myfield".
var myfield = document.getElementById("myfield");
// Attach an event listener to "myhref", which gets notifier when "myhref" is clicked.
myhref.addEventListener("click", function() {
// "myhref" is click. So, uncheck "myfield"
myfield.checked = false;
});
</script>
</body>
</html>
答案 1 :(得分:0)
我不清楚你想要什么?但这可能会对你有所帮助
function uncheck()
{
document.getElementById('myfield').checked=false;
}
在锚标记的onclick中调用此函数。
简要说明你为什么要这样做?以及你想要实现的目标,然后我们可以思考并提供任何其他更好的方法。