有一些错误:
更改: if ( $('option[name=oage]:checked').val() != undefined ) {
致: if ( $('select[name="oage"] option:checked').val() != undefined ) {
更改:$('input[name=odeliv]').change(compute);
到:$('input[name="odeliv"]').on('input', compute);
为了将文本转换为数字,您可以在 val() 之前添加一个 + 号:
+$('input[name=odeliv]').val();
片段:
function compute() {
if ( $('select[name="oage"] option:checked').val() != undefined ) {
var a = +$('input[name=odeliv]').val();
var b = +$('select[name=oage]').val();
var c = +$('select[name=otime]').val();
var total = (b * c) + a;
$('#result').val(total);
}
}
$(function () {
$('select[name="oage"]').on('change', compute);
$('input[name="odeliv"]').on('input', compute);
$('select[name="otime"]').on('change', compute);
$('input[name="odeliv"]').trigger('input');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<select name="oage">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input name="odeliv" type="number" value="1">
<select name="otime">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input name="result" id="result" type="number" value="">
</form>