简体   繁体   English

使用来自数据库的选中值显示/隐藏基于单选按钮的 Div

[英]Show/Hide Divs based on Radio Buttons with checked values coming from a database

how to Show/Hide Divs based on Radio Buttons with checked values coming from a database i am using php and sql如何使用来自数据库的选中值显示/隐藏基于单选按钮的 Div 我正在使用 php 和 sql

<input type="radio" name="status" value="Ongoing" checked="checked">Ongoing<br>
<input type="radio" name="status" value="Comming">Comming<br>
<input type="radio" name="status" value="End">End<br>

<div>div for ongoing</div>
<div>div for Comming</div>
<div>div for End</div>

The following could be helpful to solve your issue (please note the usage of data-* attribute in the div element):以下内容可能有助于解决您的问题(请注意 div 元素中data-*属性的用法):

 var radio = document.querySelectorAll('[name=status]'); radio.forEach(r => r.addEventListener('click', function(){ var v = this.value; document.querySelectorAll('div').forEach(d => { if (d.getAttribute('data-value') == v){ d.style.display = 'block'; } else{ d.style.display = 'none'; } }); }));
 [data-value = "Comming"],[data-value = "End"]{ display: none; }
 <input type="radio" name="status" value="Ongoing" checked="checked">Ongoing<br> <input type="radio" name="status" value="Comming">Comming<br> <input type="radio" name="status" value="End">End<br> <div data-value="Ongoing">div for ongoing</div> <div data-value="Comming">div for Comming</div> <div data-value="End">div for End</div>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM