尝试使用 jQuery 对某些输入字段的焦点输出(模糊或失去焦点)进行总计一些值。
以下是我正在使用的函数,但无论触发事件时在输入中找到什么,“newAmount”警报都完全空白:
//update personnel list total on blur
$('.personnel-list').focusout(function(){
var currTotal = $('#personnel-office-total').val();
var newAmount = $(this).val();
var newTotal = currTotal+newAmount;
$('#personnel-office-total').val(newTotal);
alert(currTotal);
alert(newAmount);
});
<li><label for="personnel-office-other">Other</label><input type="text" class="small-input personnel-input" name="personnel-office-other-dummy" id="personnel-office-other" /></li>
<li><label for="personnel-office-total">Total <em class="formee-req">*</em></label><input readonly="readonly" type="text" class="required small-input" name="personnel-office-managers-total" id="personnel-office-total" value="0" /></li>