作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 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/
我是一名优秀的程序员,十分优秀!