简体   繁体   English

为什么我在IE8中收到“对象预期”错误?

[英]Why am I getting an “object expected” error in IE8?

This code: 这段代码:

function foo(){
    var x = 5;
    var y = "8.8";
    var exp1 = typeof(2 * y);
    var exp2 = typeof(x + y);
    var exp3 = typeof(parsefloat(x + y));
    var exp4 = typeof(x + parsefloat(y));
    var exp5 = typeof(x + parseint(y));
    var exp6 = typeof(x-y);
    var exp7 = typeof(x*y);
    alert( exp1 + ", " + exp2 + ", " + exp3 + ", " + exp4 + ", " + exp5 + ", " + exp6 + ", " + exp7 + "." );
}

Gives me an "object expected" error on the line starting with var exp3 , character 2. 在以字符2 var exp3开头的行上给我一个“期望对象”错误。

Edit: 编辑:

Not necessary, but why is it an error on character 2? 不必要,但是为什么字符2会出错?

JavaScript is case-sensitive. JavaScript区分大小写。 Use parseFloat and parseInt . 使用parseFloatparseInt

parsefloat(x + y)

should be 应该

parseFloat(x + y) // capital F

and

parseint(y)

should be 应该

parseInt(y) // capital I

It's "parseFloat" and "parseInt". 它是“ parseFloat”和“ parseInt”。 JavaScript is case-sensitive. JavaScript区分大小写。

parsefloatparseint分别更改为parseFloatparseInt

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

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