我这里有代码,如果选中该复选框,它将乘以复选框的值和下拉列表的值,并将产品显示到文本区域。我的问题是即使未选中复选框,当您更改保管箱的值时,它仍会执行操作并显示值的乘积。如果我取消选中该复选框,它也不会将文本区域的值恢复为0.以下是代码
<table align=center border=1>
<tr colspan=3>
<td colspan=3><h2>Specialty Cakes</h2></td>
</tr>
<tr>
<td><center><img src=special\blackforest_small.jpg ><br>Black Forest</center></td>
<td><input type="checkbox" id="check1" name="check1" value="550.00"onclick="special1()">Buy P550.00</input><br><input type="text" id="total1" name="total1" value="P0.00"size="8"></input><br>
QTY: <select id="qty1" name="qty1" onchange="special1()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</td>
</tr>
</table>
<script>
function special1(){
var m = document.getElementById("check1").checked;
var x = document.getElementById("check1").value;
var y = document.getElementById("qty1").value;
var z = 0;
if (m = true){
z = "P" + x * y;
}
document.getElementById("total1").value = z;
}
</script>
答案 0 :(得分:1)
请更改此
if (m = true){
z = "P" + x * y;
}
喜欢以下
if (m == true){
z = "P" + x * y;
}
你应该使用“==”运算符进行比较