点击“从日期选择推文数量”后,必须删除“选择结束日期”输入字段。有人可以帮我吗?这是代码:
function yesnoCheck() {
if (document.getElementById('yesCheck').checked) {
document.getElementById('ifYes').style.display = 'block';
} else document.getElementById('ifYes').style.display = 'none';
}
<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>
<img src="icon2.png"><label for="date">选择结束日期:</label><br>
<input type="datetime-local" id="Test_DatetimeLocal"><br><br>
<input type="submit" value="提交" class="submit">
</form>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
按照你的
#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>