P粉3279030452023-09-03 00:48:53
按照你的#ifYes
标签的方式来做。用div
将输入和标签包裹起来,给它分配一个id
,然后只需使用document.getElementById('select-end-period').style.display = 'none';
function yesnoCheck() { if (document.getElementById('yesCheck').checked) { document.getElementById('ifYes').style.display = 'block'; document.getElementById('select-end-period').style.display = 'none'; } else { document.getElementById('ifYes').style.display = 'none'; document.getElementById('select-end-period').style.display = 'block'; } }
<form> <input type="radio" onclick="javascript:yesnoCheck();" name="yesno" id="noCheck">选择期间 <br> <br> <input type="radio" onclick="javascript:yesnoCheck();" name="yesno" id="yesCheck">从日期开始的推文数量<br><br> <div id="ifYes" style="display:none"> 期望推文数量 <input type="number" min="1" max="20" id='yes' name='yes'><br> </div> <br> <img src="icon2.png"><label for="date">选择开始日期:</label><br> <input type="datetime-local" id="Test_DatetimeLocal"><br><br> <div id="select-end-period"> <img src="icon2.png"><label for="date">选择结束日期:</label><br> <input type="datetime-local" id="Test_DatetimeLocal"><br><br> </div> <input type="submit" value="提交" class="submit"> </form>