【发布时间】:2017-02-04 13:13:08
【问题描述】:
这是在我的注册表单中,当我选中其中一个单选按钮时,应禁用带有占位符“指定”的输入类型文本。除非我选中单选按钮“其他”。这是为了指定注册人的位置。
<label for="position"><b>Position:</b></label><br/><br/>
<input type="radio" name="position" id="r1" value="Dean" />Dean
<input type="radio" name="position" id="r2" value="Instructor"/>Instructor
<input type="radio" name="position" id="r3" value="Student"/>Student<br/><br/>
<input type="radio" name="position" id ="r4" value="<?php echo $_POST['otherPosition']?>"/>
Others:
<input type="text" value = "<?php if($error==TRUE){echo $_POST['otherPosition'];}?>" id="otherPosition" placeholder="Specify" name="position"/>
这是我的 Javascript
<script>
if(document.getElementById('r1').checked||document.getElementById('r2').checked||document.getElementById('r3').checked){
document.getElementById('otherPosition').readOnly = true;
}else{
document.getElementById('otherPosition').readOnly = false;
}
</script>
【问题讨论】:
-
您的代码将在页面加载时运行一次,而不是响应用户单击收音机。 (另外,顺便说一句,“禁用”和“只读”不是一回事。)
-
多个重复/相关问题可以通过Googling the title of this question找到。还有一次,最好尝试搜索您用于问题的标题(或关键字),看看是否有可用的资源可以为您提供答案。这样做通常可以比花精力写出问题更快地找到解决方案。
标签: javascript html css