为什么某些 JavaScript 函数在 Google Chrome 中无法运行,但在 Mozilla Firefox 中运行良好?
像这样..
HTML 代码:
...
onkeyup="calculateTotal(this.value)"
onclick="clickclear(this, '0')" onblur="clickrecall(this,'0')" value="0"
JS代码:
function calculateTotal(price, quantity, cnt) {
if(quantity != ""){
var totalAmt = parseInt(document.getElementById('total['+cnt+']').value);
totalAmt = parseInt(quantity) * parseInt(price);
document.getElementById('total['+cnt+']').value = totalAmt;
document.getElementById('indicator').value++;
}
else{
document.getElementById('total['+cnt+']').value = 0;
document.getElementById('indicator').value--;
}
}
并且已经包含了这个:
jquery1.4.2.js
最佳答案
您正在调用该函数
calculateTotal(this.value)
但是你的功能是:
function calculateTotal(price, quantity, cnt)
我不知道为什么这在 Firefox 中有效(我假设它们自动提供参数或其他东西),但你的两个函数不匹配。
关于谷歌浏览器中的 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3529059/