SCRIPT5007:无法获取属性'indexOf'的值:对象在IE中为null或未定义 [英] SCRIPT5007: Unable to get value of the property 'indexOf': object is null or undefined in IE

查看:930
本文介绍了SCRIPT5007:无法获取属性'indexOf'的值:对象在IE中为null或未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IE中遇到此错误。它适用于所有其他浏览器。

Hi I got this error in IE. It works in all other browsers.

这是错误显示的行:

if (parseFloat(totalnumm.replace(/[^0-9-.]/g,'')) > compare_value_neww    &&  values[x].indexOf("Custom") > -1 ).

我用Google搜索并找到了一个解决方案:

I googled and found one solution:

<meta http-equiv="X-UA-Compatible" content="IE=8;FF=3;OtherUA=4" />

但它对我不起作用。

推荐答案

我打算问你在测试这个版本的IE,但是因为你已经指定 content =IE = 8 在您的元标记中,这是相当无关紧要的。

I was going to ask what version of IE you're testing this in, but since you've specified content="IE=8 in your meta tags, that's fairly irrelevant.

简短的回答是数组的 .indexOf 是在IE8或更早版本中不受支持。(其中包括兼容模式下的IE版本,因此您的元标记将意味着它不适用于任何IE版本)

The short answer is that .indexOf for arrays is not supported in IE8 or earlier. (That includes later IE versions in compatibility mode, so your meta tag will mean that it won't work in any IE version)

解决方案:


  1. 使用像jQuery(或类似)这样的库来提供 .inArray( )您可以使用的方法。

  1. Use a library like jQuery (or similar) which supplies an .inArray() method that you can use instead.

然后,您需要使用 var.indexOf(x) to $。inArray(var,x)

You'll then need to change your code from using var.indexOf(x) to $.inArray(var,x)

如果您已经在使用jQuery(或具有此功能的其他库),请选择此解决方案。

Pick this solution if you're already using jQuery (or another library that has this feature).

使用polyfill libra像这一个添加标准 .indexOf 数组原型的方法。

Use a polyfill library like this one that adds the standard .indexOf method to the Array prototype.

这可以让你保持现有代码不变;只需包含该库。

This should allow you to keep your existing code unchanged; just include the library.

如果您愿意使用库但尚未安装可以提供帮助的库,请使用此解决方案。

Use this solution if you are happy to use a library but you haven't got one already installed that would help.

编写自己的函数,使用 for()循环执行相同的工作。

Write your own function that does the same job using a for() loop.

这是您在数组中查找内容的完全变化,但这意味着您不需要使用任何额外的库。

This is a complete change in how you find things in your arrays, but does mean you don't need to use any extra libraries.

如果您不想(或不能以任何理由)使用第三方库,请使用此解决方案。

Use this solution if you don't want to (or can't, for whatever reason) use a third-party library.

删除您的IE8元标记(无论如何都非常糟糕,所以这是一个好主意)并且仅为IE9或更高版本的用户支持您的网站。

如果您愿意停止支持旧的IE版本,请使用此解决方案。

Use this solution if you're happy to stop supporting older IE versions.

事实上,无论如何都要这样做是个好主意。没有充分的理由使用元标记强制IE进入兼容模式。最好将其设置为 content =IE = edge。这将完全消除新IE版本的问题。如果您确实需要支持IE8或更早版本,那么此解决方案无法解决问题,您还需要使用上述其他解决方案之一,但无论如何我仍然建议您这样做,因为事实证明你是故意从新的IE版本中删除功能。

In fact, it would be a good idea to do this anyway; there's no good reason to be using the meta tag to force IE into compatibility mode. Better to set it to content="IE=edge". That will remove the problem entirely for newer IE versions. If you do need to support IE8 or earlier, then this solution won't solve the problem and you'll need to also use one of the other solutions above, but I'd still recommend doing it anyway, because as things stand you are deliberately removing features from newer IE versions for no good reason.

这篇关于SCRIPT5007:无法获取属性'indexOf'的值:对象在IE中为null或未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆