我有一个 HTML 表单,其中包含四组选择选项selector、selector2、selector3和selector4。我正在尝试添加所选选项的值,但失败了。我该如何总结?在我的代码中,只将值像字符串一样打印在一起。function graffar() { var graffarA = document.getElementById('list2').value; var graffarB = document.getElementById('list3').value; var graffarC = document.getElementById('list4').value; var graffarD = document.getElementById('list5').value; var graffartotal = graffarA + graffarB + graffarC + graffarD; alert(graffartotal) return;}<form action="" class="specialform"> <fieldset> <legend>(Graffar)</legend> <label for="job">Condition</label> <select name="selector" id="list2" class="decorated" onchange="getValueOp ();"> <option value="null">Choose</option> <optgroup label="Condition"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </optgroup> </select> <label for="job">Condition 2 </label> <select name="selector2" id="list3" class="decorated" onchange="getValueOp ();"> <option value="null">Choose</option> <optgroup label="Condition2"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </optgroup> </select> <label for="job">Condition 3</label> <select name="selector3" id="list4" class="decorated" onchange="getValueOp ();"> <option value="null">Selecciona un rango</option> <optgroup label="Condition3"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </optgroup> </select>
1 回答
慕莱坞森
TA贡献1810条经验 获得超4个赞
您可以使用parseInt函数将字符串值转换为数字。例如:
var graffarA = parseInt(document.getElementById('list2').value);
添加回答
举报
0/150
提交
取消