我想要的是,只有从下拉菜单中选择某个选项并且我有一个html表单如下所示,才能访问该文本框:
<tr>
<td>a. Did any of your staff participate in training or orientation sessions related to any aspect of social performance management, during the reporting year? </td>
<td >
<p>
<select name="mfi_4_a_i">
<option>Yes</option>
<option>No</option>
<option>No, but planning in future</option>
</select>
</p>
<p>if not,and not planning please explain why not </p>
<input type="text" name="mfi_4_a_ii" id="sdd" />
</tr>
Run Code Online (Sandbox Code Playgroud)
现在,当用户选择选项No,但将来计划时,必须启用文本框,否则必须禁用文本框.
我该如何做到这一点?
你应该为此调用javascript函数.
<select id="mfi_4_a_i" name="mfi_4_a_i" onChange="changetextbox();">
<option>Yes</option>
<option>No</option>
<option>No, but planning in future</option>
</select>
<input type="text" name="mfi_4_a_ii" id="sdd" />
<script type="text/javascript">
function changetextbox()
{
if (document.getElementById("mfi_4_a_i").value === "noy") {
document.getElementById("sdd").disable='true';
} else {
document.getElementById("sdd").disable='false';
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
小智 8
对我来说,document.getElementById("sdd").disabled='false'没用,所以我用过
document.getElementById("sdd").disabled='';
if (document.getElementById("mfi_4_a_i").value === "noy") {
document.getElementById("sdd").disabled='true';
} else {
document.getElementById("sdd").disabled='';
}
Run Code Online (Sandbox Code Playgroud)