表单逻辑适用于Chrome,而不适用于IE

时间:2015-08-31 16:57:05

标签: javascript html internet-explorer

我有一个带有输入字段的基本HTML表单,我想开始禁用它,但是根据之前的选择输入更改为启用。这适用于Chrome但在IE中失败...可能是一件非常容易的事情,但我找不到解决方案..

<script language="javascript">
function enableFeedback(val)
{
    if(val == "Feedback"){
    document.frmQuestionnaire.txtAns3.disabled=false;
}
else {
    document.frmQuestionnaire.txtAns3.value="";
    document.frmQuestionnaire.txtAns3.disabled=true;

}
}
</script>

<td valign="top" colspan="3"><select name="select" onChange="enableFeedback(this.value)">
            <option>Select an option...</option>
            <option>Feedback</option>
            <option>No feedback</option>
    </select></td>
   </tr>
   <tr>
    <td valign="top" align="left" width="92" bgcolor="#ffffff"><font size="2" face="Arial, Helvetica, sans-serif">Comments:</font></td>
    <td valign="top" colspan="3"><input name="txtAns3" size="6" disabled="disabled"></td>

1 个答案:

答案 0 :(得分:0)

<script language="javascript">
function updateFeedback(val)
{
val=+val;
var txtElem = document.getElementById("txtAns3");
txtElem.disabled=val?"":"disabled";
val||(txtElem.value="");
}
</script>

<td valign="top" colspan="3">
<select name="select" onChange="updateFeedback(this.options[this.selectedIndex].value)">
            <option value="0">Select an option...</option>
            <option value="1">Feedback</option>
            <option value="0">No feedback</option>
    </select></td>
   </tr>
   <tr>
    <td valign="top" align="left" width="92" bgcolor="#ffffff"><font size="2" face="Arial, Helvetica, sans-serif">Comments:</font></td>
    <td valign="top" colspan="3">
    <input id="txtAns3" name="txtAns3" size="6" disabled></td>