Javascript页面加载总数
问题描述:
我创建了一个用于计算每月费用的表单。我遇到的问题是我收集前一页(会话到数据)的信息的最后一页,该信息自动填充最后一页上的字段。我创建了一个JavaScript,假设总页数减去五个字段,但这不起作用。如果我将会话从加载部分删除数据,JavaScript完美地工作。Javascript页面加载总数
页的问题: http://www.garranteedsolutions.com/budget?chronoform=BudgetPage7
的Javascript:
window.addEvent('domready', function() {
$('spendable').addEvent('change', rekenen1);
$('housetotal').addEvent('change', rekenen1);
$('cartotal').addEvent('change', rekenen1);
$('creditortotal').addEvent('change', rekenen1);
$('misctotal').addEvent('change', rekenen1);
});
function rekenen1(){
$('grandtotal').value = Number($('spendable').value) + Number($('housetotal').value) + Number($('cartotal').value) + Number($('creditortotal').value) + Number($('misctotal').value) ;
}
这是我一直在使用的代码,但它需要在表格框的改变要执行的操作。我已经试过这
的Javascript:
window.addEvent('domready', function() {
rekenen1;
$('spendable').addEvent(rekenen1);
$('housetotal').addEvent(rekenen1);
$('cartotal').addEvent(rekenen1);
$('creditortotal').addEvent(rekenen1);
$('misctotal').addEvent(rekenen1);
});
function rekenen1(){
$('grandtotal').value =
Number($('spendable').value) + Number($('housetotal').value)
+ Number($('cartotal').value) + Number($('creditortotal').value)
+ Number($('misctotal').value);
}
这是我的延续寻求帮助,从这里开始:http://www.chronoengine.com/forums/viewtopic.php?f=2&t=67427&p=269741#p269741
我不知道的Javascript非常好,我很接近完成此表格。我只是无法让Grand Total合计。
答
这似乎工作!所以现在我想弄清楚如何得到成千上万的逗号。所以如果我输入1200就会显示1,200。
window.addEvent('domready', function() {
$('grandtotal').value = Number($('spendable').value) + Number($('housetotal').value) + Number($('cartotal').value) + Number($('creditortotal').value) + Number($('misctotal').value);
});
非常感谢您的帮助!
答
问题是,只有当您更改表单的值时才触发事件。它的只读形式,所以他们不能改变。
不管怎么说,这是优化代码:
window.addEvent('domready', function() {
var rekenen1 = function(){
var grandTotal = 0;
$$('#spendable, #housetotal, #cartotal, #creditortotal, #misctotal').each(function(el){
if(el.value.length > 0) grandTotal += el.value.toFloat();
});
$('grandtotal').value = grandTotal;
};
$$('#spendable, #housetotal, #cartotal, #creditortotal, #misctotal').addEvent('onchange', refenen1);
});
这应该工作。该函数检查这些字段是否对它们有价值,如果它们有,则将它们包含在计算中。
由于缺少addEvent函数中的参数,因此引发的第二个代码触发了错误。
我希望这可以帮助你:)
这不起作用。控制台说以下内容: '未捕获的ReferenceError:refenen1没有定义 rokboxPathbudget:76 (匿名功能)的mootools-core.js:370 hmootools-core.js:33个 Array.implement.eachmootools核。 js:39 invoke.fireEventmootools-core.js:369 g' 我需要将只读关掉吗?我真的很想这样,最终用户不能改变总数。 – 2012-03-18 19:13:16
它称为rekenen1的函数不是refenen1。我认为你拼错了这个名字 – ajimix 2012-03-19 13:29:13