如何应用复选框与JavaScript中的函数? [英] How to apply checkbox with functions in javascript?
问题描述
如何在javascript中使用函数复选框?
How to apply checkbox with functions in javascript?
如果未选中复选框,如何使用特定标记隐藏帖子/对象?
How to hide post/object with specific tags when checkbox is unchecked?
我只需要知道如何使复选框的功能在打开页面时自动检查,以及复选框以隐藏具有特定标签的帖子/对象。是否正确应用 -
I just need to know how to put functions for the checkbox to be automatically check upon opening the page and the checkbox to hide posts/objects with a specific tag on them. Is it correct to apply--
display:none
或 -
.structural {
position:absolute;
left:-9999px;
}
- 我在研究过程中发现了吗?
--that I've found during research?
这是我考虑到我缺乏技能的地方:
This was as far as I could go considering my lack of skills:
<input
type="checkbox"
name="mycheckbox"
value="yes"
onclick=" CheckboxChecked(this.checked,'checkboxdiv')"
</div>
</div>
<script type="text/javascript">
CheckboxChecked(document.myform.mycheckbox.checked,'checkboxdiv');
</script>
推荐答案
如果我正确理解你的问题,当选中/取消选中复选框时,隐藏/显示一组元素。这应该足以让你去:
If I understood your question correctly, you are attempting to hide/show a group of elements when a checkbox is checked/unchecked. This should be enough to get you going:
HTML:
<div class="hideWhenChecked">hide text</div>
<div>dont hide text</div>
<div class="hideWhenChecked">hide text</div>
<div>dont hide text</div>
<br />
<input type="checkbox" id="myCheckBox" />
JavaScript:
JavaScript:
document.getElementById('myCheckBox').addEventListener('click', function () {
var checked = this.checked;
var elementsToHide = document.getElementsByClassName('hideWhenChecked');
if (checked) {
// hide each element
} else {
// show each element
}
});
我建议调查一下javascript框架,如jQuery,更简单。
I'd suggest looking into a javascript framework such as jQuery to make this code a lot simpler.
这篇关于如何应用复选框与JavaScript中的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!