我正在使用jQuery键盘构建销售点界面
http://keith-wood.name/keypadBasics.html
我有两个文本字段,即
以前的租金和已付的租金
当用户输入数据时,我希望页面实时运行以下公式
以前的租金-已付的租金
我希望它能实时显示文本字段下的结果(无需刷新页面或提交代码)
如何做到这一点?
发布于 2010-11-05 04:25:04
绑定到change
或blur
应该可以工作。
<html>
<body>
<script src='jquery.js'></script>
<script>
$(document).ready(function(){
$('#previousRent').change(function(){
calcResult();
});
$('#rentPaid').change(function(){
calcResult();
});
});
function calcResult() {
$('#result').val( parseFloat($('#previousRent').val() - $('#rentPaid').val()) );
}
</script>
<input type="text" id="previousRent">
<input type="text" id="rentPaid">
<input type="text" id="result">
</body>
</html>
发布于 2010-11-05 04:19:28
假设您想要在“已付租金”字段失去焦点时进行更新:
$('#rent-paid').blur(function({
var diff = $('#previous-rent').attr('value') - $(this).attr('value');
$('#total').text(diff);
}));
https://stackoverflow.com/questions/4100869
复制相似问题