简体   繁体   English

JavaScript无法在Google Chrome浏览器中使用

[英]JavaScript not working in Google Chrome

What's the reason why some JavaScript functions won't work in Google Chrome but works fine in Mozilla Firefox? 为什么某些JavaScript函数不能在Google Chrome浏览器中运行但在Mozilla Firefox中可以正常运行的原因是什么?

Like this.. 像这样..

HTML code: HTML代码:
... ...

onkeyup="calculateTotal(this.value)" 
onclick="clickclear(this, '0')" onblur="clickrecall(this,'0')" value="0"

JS code: 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--;

    }
}

And already included this: 并且已经包括了:
jquery1.4.2.js jquery1.4.2.js

You're calling the function 您正在调用该函数

calculateTotal(this.value)

but your function is: 但您的功能是:

function calculateTotal(price, quantity, cnt)

I don't know why this DOES work in Firefox (I'm assuming they automatically supplied parameters or something), but your two functions do not match up. 我不知道为什么这样做在Firefox中有效(我假设它们会自动提供参数或其他东西),但是您的两个功能不匹配。

From the html 4 spec: 从html 4规范:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). ID和NAME令牌必须以字母([A-Za-z])开头,后跟任意数量的字母,数字([0-9]),连字符(“-”),下划线(“ _”) ,冒号(“:”)和句点(“。”)。

http://www.w3.org/TR/html401/types.html#type-name http://www.w3.org/TR/html401/types.html#type-name

I would therefore replace your use of square brackets in ids before trying anything else. 因此,在尝试任何其他操作之前,我将替换您在id中使用方括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM