怀疑我做了一些愚蠢的事情,但我现在看不到木头的树木了。另一双眼睛可能会立即解决这个问题。
<script>
function ChkStatus1() {
if (document.frm1.LabelReq_1.value = "1") {
document.frm1.LabelReason_1[0].selected = true;
document.frm1.LabelReason_1.disabled = true;
}
if(document.frm1.LabelReq_1.value = "0") {
document.frm1.LabelReason_1.disabled = false;
}
}
</script>
<Select name="LabelReq_1" onchange="ChkStatus1();">
<option value="1">Yes</option>
<option value="0">No</option>
</Select>
<Select name="LabelReason_1" disabled="disabled">
<option>[Please select why not required]</option>
<option>Reason 1</option>
<option>Reason 2</option>
<option>Reason 3</option>
<option>Reason 4</option>
<option>Reason 5</option>
</Select>
当我选择No时,一切都按照我的预期进行,但是当我选择'Yes'时它会执行'LabelReason_1 [0] .selected = true;'但随后不会更改LabelReq_1组合框。
谁能看到我哪里出错了?
提前致谢
格雷姆
答案 0 :(得分:4)
将if语句中的=更改为==
=赋值,==表示相等
<script>
function ChkStatus1() {
if (document.frm1.LabelReq_1.value == "1") {
document.frm1.LabelReason_1[0].selected = true;
document.frm1.LabelReason_1.disabled = true;
}
if(document.frm1.LabelReq_1.value == "0") {
document.frm1.LabelReason_1.disabled = false;
}
}
</script>
答案 1 :(得分:1)
您需要使用==或===而不是=:
<script>
function ChkStatus1() {
if (document.frm1.LabelReq_1.value == "1") {
document.frm1.LabelReason_1[0].selected = true;
document.frm1.LabelReason_1.disabled = true;
}
if(document.frm1.LabelReq_1.value == "0") {
document.frm1.LabelReason_1.disabled = false;
}
}
</script>