[英]how can click radio then display div or hidden
when I onclick the radio,当我 onclick 收音机时,
how can display or hidden the div?如何显示或隐藏 div?
because I writing this code, it cannot work.因为我写了这段代码,它不能工作。
<div class="col-12 gap-24"><div class="row"><span class="col-2"><input class="" type="radio" name="payway" value="5" οnclick="myFunction();">Store</span></div></div>
</div>
<script>
function myFunction() {
var check_pick = document.getElementById("check_pick");
var check_pick1 = document.getElementById("check_pick1");
if (check_pick.style.display === "none") {
check_pick.style.display = "block";
} else {
check_pick.style.display = "none";
}
if (check_pick1.style.display === "none") {
check_pick1.style.display = "block";
} else {
check_pick1.style.display = "none";
}
}
</script>
<label class="h4" name="check_pick" id="check_pick">Pick up method</label>
<div class="row_4 border" name="check_pick1" id="check_pick1">
set up your listener after window has loaded在 window 加载后设置你的监听器
window.onload = function() { /* you can assign a listener like this: var radio = document.getElementById('radio'); radio.onclick = myFunction; or like this: */ document.getElementById("radio").addEventListener("click", myFunction); var check_pick = document.getElementById("check_pick"); check_pick.style.display='none' var check_pick1 = document.getElementById("check_pick1"); check_pick1.style.display='none' } function myFunction() { var check_pick = document.getElementById("check_pick"); var radio = document.getElementById("radio"); var check_pick1 = document.getElementById("check_pick1"); if (check_pick.style.display === "none") { check_pick.style.display = "block"; } else { check_pick.style.display = "none"; radio.checked = false } if (check_pick1.style.display === "none") { check_pick1.style.display = "block"; } else { check_pick1.style.display = "none"; } }
#check_pick,#check_pick1{ display:none;}
<div class="col-12 gap-24"> <div class="row"> <input id='radio' type="radio" name="payway" value="5" />Store </div> </div> <label class="h4" name="check_pick" id="check_pick">Pick up method</label> <div class="row_4 border" name="check_pick1" id="check_pick1">xxx</div>
The really nasty problem with the posted code is the presence of the greek letter ο , namely a greek omicron character in lower case, in the attribute value οnclick="myFunction()
. This stops the onclick attribute being recognized without generating an error:发布代码的真正令人讨厌的问题是希腊字母ο的存在,即小写的希腊 omicron 字符,在属性值
οnclick="myFunction()
中。这会阻止 onclick 属性被识别而不会产生错误:
console.log( 'οnclick="myFunction();"' === 'onclick="myFunction();"' ); console.log("0x0" + 'οnclick="myFunction();"'.charCodeAt(0).toString(16));
You may wish to investigate where the omicron came from.您可能希望调查 omicron 的来源。 Hopefully it was caused by selecting the wrong keyboard language when originally typed in.
希望这是由于最初输入时选择了错误的键盘语言造成的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.