我有这个table,我无法在td中使用函数计算器。
该脚本完美无缺,但是当我编辑单元格中的数字时(只需单击单元格以获取输入数字),我就无法获得总结果。你能解释我应该对我的可插入插件应用哪个事件吗?您知道可能有不同或更好的方法来实现这一目标吗?
由于
答案 0 :(得分:0)
您应该使用callback
事件并指定正确的事件处理程序来计算总数。
检查此代码是否有效,如果认为需要,请添加更多操作。
你的代码对我来说很奇怪,但无论如何它都有效。
函数tally
应在onrender
$(function(){ ... });
块之外定义为全局函数。
<script type="text/javascript">
function tally (selector) {
$(selector).each(function () {
var total = 0,
column = $(this).siblings(selector).andSelf().index(this);
$(this).parents().prevUntil(':has(' + selector + ')').each(function () {
total += parseFloat($('p#sum:eq(' + column + ')', this).html()) || 0;
})
$(this).html(total);
});
}
$(function() {
tally('p#subtotal');
tally('p#total');
});
</script>
<script type="text/javascript" charset="utf-8">
$(function() {
$('.editable_number').editable(function(value, settings) { return(value); }, {
type : 'number',
style : "inherit",
callback: function() {
tally('p#subtotal');
tally('p#total');
}
}
);
$('.editable_textarea').editable(function(value, settings) { return(value); }, {
type : 'textarea',
width: '200',
height: '20',
submit : 'OK',
style : "inherit"
});
});
</script>