是否可以根据所选选项进行计算?
这是我的代码:
<input type="text" id="resultBox" readonly="true" />
<select id="select1">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
<select id="select2">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
答案 0 :(得分:1)
应该是这样的
function result() {
alert("alert");
var select1_var1;
var select1_var2;
var select1Option = document.getElementById("select1").value;
var select1_control = 10;
var select2Option = document.getElementById("select2").value;
var select2_Value = 20;
if (select1Option = "A"){
select1_var1 = null;
select1_var2 = 0;
}
if (select2Option = "C"){
select1_var1 = select2_Value * 50;
select1_var2 = select2_Value * 100;
}
var result = (select1_var1 + select1_var1) / (select1_var2 + select1_var2)
document.getElementById('resultBox').value=result;
}