我想隐藏复选框并显示div类。
到目前为止,我有代码隐藏div但没有显示它。我知道我以某种方式做错了!我有多个复选框
继承我的代码
<script type="text/javascript">
function show(target) {
document.getElementById(target).style.display = 'block';
}
function hide(target) {
document.getElementById(target).style.display = 'none';
}
</script>
<tr>
<th><input onclick="hide('tester')" type="checkbox" checked>
我知道它与onclick hide有关。将它作为一个切换会更好吗?
萨姆
答案 0 :(得分:4)
您需要使用单个处理程序,根据检查状态,您可以设置显示值,如
function showhide(el, target) {
document.getElementById(target).style.display = el.checked ? 'block' : 'none';
}
<input onclick="showhide(this, 'tester')" type="checkbox" checked />
<div id="tester">tester</div>
使用jQuery
$('#mycheckbox').change(function() {
$('#tester').toggle(this.checked)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input id="mycheckbox" type="checkbox" checked />
<div id="tester">tester</div>
答案 1 :(得分:1)
试试这个
function toggle(target) {
if(document.getElementById(target).style.display=="block")
document.getElementById(target).style.display = 'none';
else
document.getElementById(target).style.display = 'block';
}
<input onclick="toggle('toggle')" type="checkbox" checked>
<div id="toggle">Show and hide</div>
答案 2 :(得分:1)
试试这个:
var thumbsUp = element(by.css('span.glyphicon-thumbs-up'));
var thumbsDown = element(by.css('span.glyphicon-thumbs-down'));
it('should check ng-show / ng-hide', function() {
expect(thumbsUp.isDisplayed()).toBeFalsy();
expect(thumbsDown.isDisplayed()).toBeTruthy();
element(by.model('checked')).click();
expect(thumbsUp.isDisplayed()).toBeTruthy();
expect(thumbsDown.isDisplayed()).toBeFalsy();
});