简体   繁体   English

我想从3复选框中选择一个复选框,如果没有选中则显示div在简单的javascript中隐藏div

[英]i want select one checkbox from 3 checkbox and display div if none is seletced hide div in simple javascript

i am able to select any one checkbox but i am displaying div more time as i select checkbox here is the check box: 我可以选择任何一个复选框,但是我在显示div的同时显示了更多时间,这是该复选框:

<INPUT type=CHECKBOX id='IP_3820' IP='12.12.12.12' PORT='5060' onclick='javascript: ipSelected(this)' value='3820' >12.12.12.12
<br />
<INPUT type=CHECKBOX id='IP_3822' IP='12.12.12.13' PORT='5060' onclick='javascript: ipSelected(this)' value='3822' >12.12.12.13

This div i want to display as check any one checkbox: 我想将此div显示为选中任何一个复选框:

<div id='vp_3822' style='float:right;display:none;'>
    <input type='radio' name='3822' id='IP_none' value='none' /> NONE / 
    <input type='radio' name='3822' id='g729' value='g729'  />g729/ 
    <input type='radio' name='3822' id='ulaw' value='ulaw' checked='checked' />ulaw
</div><br />

This is the function: 这是功能:

function ipSelected(el){
    if(el.checked){
        document.getElementById("IP_none").checked=false;
        if(last_ip_id!="" && last_ip_id!=el.id && ( document.getElementById('system').value=='voipswitch' || document.getElementById('system').value=='asterisk' || document.getElementById('system').value=='ipsmarx')){
            try { document.getElementById(last_ip_id).checked=false;}catch(e){}
        }
        last_ip_id = el.id;
        document.getElementById("vp_" + el.value).style.display="block";
        // Set destination value
        if((document.getElementById('system').value=='voipswitch') || (document.getElementById('system').value=='asterisk' || document.getElementById('system').value=='ipsmarx')){
            document.getElementById('dest_span').innerHTML = "@" + el.getAttribute("IP") + ":" + el.getAttribute("PORT");
            document.theForm.idiplist.value = el.value;
        }
    }
}

It is because you keep displaying the divs on each checkbox's check but have forgotten to hide the rest of the divs 这是因为您一直在每个复选框的复选框上显示div,但忘记隐藏其余的div

add a class all the divs say divClass 添加一个类,所有div都说divClass

then use the below code to display the correct div and keep the others hidden 然后使用下面的代码显示正确的div并隐藏其他

$(".divClass").hide();
$("#vp_"+el.value).show();

Hide Div in javascript 在JavaScript中隐藏Div

document.getElementById('"#vp_"+el.value').style.display = 'none';

Show Div in javascript 在JavaScript中显示Div

 document.getElementById('"#vp_"+el.value').style.display = 'block';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 复选框 select = 名称显示从 ajax 到 div? - Checkbox select = the name is display from the ajax to the div? 我有 3 个 Div,如何通过单击(一个接一个)选择 2 个 div 并在 Javascript 中不显示(或其他)第三个 - I have 3 Div, how to select 2 div with a click (one by one) and to display none (or other) the third one in Javascript 当我单击复选框时,我想使用Bootstrap和JavaScript显示或隐藏div - when i click on checkbox then i want to show or hide a div using bootstrap and javascript 想要在选中复选框时显示特定的div,如果未选中则隐藏div。不起作用IE8 / IE9 - Want to display a particular div on checking a checkbox and if it is left unchecked then hide div .Not working IE8/IE9 复选框以隐藏div - checkbox to hide div javascript隐藏/显示div复选框:选中/取消选中 - javascript Hide/show div on checkbox: checked/unchecked Javascript复选框切换div隐藏显示 - Javascript checkbox toggle div hide show 带有“显示隐藏Div”复选框的Javascript“下一步”按钮 - Javascript “next” button with checkbox “show hide Div” 使用javascript而不是jquery“显示/隐藏”div,而不使用display:none - “show/hide” a div with javascript not jquery, and not with display:none 单击特定div时选中选择复选框 - Working on select checkbox on one click of particular div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM