gpt4 book ai didi

Javascript 输入字段仅在显示时才需要?

转载 作者:行者123 更新时间:2023-11-27 22:59:48 25 4
gpt4 key购买 nike

我是 js/jquery 的新手,希望您能够帮助我对我的脚本进行简单的编辑。我的脚本的基础是我有一组单选按钮,如果用户选择是 - 他们就完成了。但是,如果他们单击“否”,则会弹出一个新的输入框并要求提供更多信息。

不幸的是,我一直无法找到一种方法来使弹出输入框成为提交时必需的,因为当用户单击"is"时,它会出现问题,仍然是必需的,但已隐藏。

这是迄今为止我的代码:

function ShowHide(){
if(document.getElementById('spellingN').checked){
document.getElementById("spellingT").style.display = "block";
} else {
document.getElementById("spellingT").style.display = "none";
}
}

<div class="col-md-4">
<div class="radio"><b><input id="spellingY" name="spelling" onchange="ShowHide()" required="" type="radio" value="yes" /> Yes</b></div>

<div class="radio"><b><label for="radios-1"><input id="spellingN" name="spelling" onchange="ShowHide()" required="" type="radio" value="no" /> No </label></b></div>
</div>
</div>

<div id="spellingT" style="display: none;">
<div class="form-group"><b><label class="col-md-4 control-label" for="Spelling-Correction"><b>Question 2a</b> Type the grammatically correct version of the term.</label> </b>

<div class="col-md-4"><b><input class="form-control input-md" id="Grammar-Correction" name="Grammar-Correction" placeholder="" required="" style="width: 100%;" type="text" /></b></div>
</div>

我希望你能够理解它并帮助我。提前致谢!

最佳答案

您可以在您的函数中添加此检查:

if(document.getElementById('spellingT').style.display == "block"){
//your submission
}

关于Javascript 输入字段仅在显示时才需要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37209638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com