0

所以我有一个小问题:我在它旁边创建了一个下拉菜单和一个文本字段。下拉菜单中只有一个选项会导致文本字段取消显示。可以这么说,所有其他选择都应该导致文本字段锁定。

下面的代码:

</td> <td><select name="employee_type" onchange="document.getElementById('otherField').disabled=(this.value == 1, 2)">
<option value=0>Temporary</option>
<option value=1>Regular</option>
<option value=2>Special Access User</option>

<input id="otherField" type="text" name="date_expires_input" value="YYYY/MM/DD" style="color:#aaa; font-style:italic;" onclick="this.value=''; this.style.color='#000'; this.style.fontStyle='normal';" />
        </tr>

确实这样做。但是,如果用户选择“临时”然后改变主意选择“常规”,则该字段将保持为幻影。有谁知道为什么?

4

2 回答 2

1

怎么样

<select name="employee_type" onchange="document.getElementById('otherField').disabled=(this.value != 0)">

? 反过来说……你不能说this.value == 1, 2,你就不得不说this.value == 1 || this.value == 2

于 2012-06-11T12:28:34.110 回答
1

你的情况应该是

document.getElementById('otherField').disabled = (this.value == 1 || this.value == 2)
于 2012-06-11T12:27:15.190 回答