用JS把复选框做成单选框,左显示div,右隐藏div

<input type="checkbox" name="checkname" onclick="check(this)"/>左
<input type="checkbox" name="checkname" onclick="check(this)"/>右

<div id="show" style="display:block;">显示</div>
<div id="hidden" style="display:none;">隐藏</div>

<script type="text/javascript">
function check(obj){
    var checks = document.getElementsByName("checkname");
    if(obj.checked){
        for(var i=0;i<checks.length;i++){
        checks[i].checked = false;
        }
        obj.checked = true;
    }else{
        for(var i=0;i<checks.length;i++){
        checks[i].checked = false;
        }
    }    
    document.getElementById('show').style.display = document.getElementById('show').style.display=="none"?"block":"none";
    document.getElementById('hidden').style.display = document.getElementById('hidden').style.display=="none"?"block":"none";    
}
</script>

 

posted @ 2016-11-25 11:16  01源代码  阅读(1355)  评论(0编辑  收藏  举报