[英]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.