代码适用于Chrome和Firefox,但在IE11中无效

时间:2016-06-24 19:31:43

标签: javascript google-chrome firefox internet-explorer-11

我有这个小程序,它基本上与数字组相比较,然后会告诉我是否有任何匹配以及这些匹配是什么。它在Chrome和Firefox中运行得很好,但是当我在IE11中尝试它并按下按钮时,什么都没有出现,它似乎不起作用。我看过其他论坛和主题,但我尝试过的任何东西似乎都没有用。有任何想法吗?

下面是代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
<HTML><HEAD><META content="IE=5.0000" http-equiv="X-UA-Compatible">

<META http-equiv="Content-Type" content="text/html; charset=unicode">
<SCRIPT>
function check() {
var a = document.getElementById("a").value.split("\n").filter(function(num) { return num.length > 0 });
var b = document.getElementById("b").value.split("\n").filter(function(num) { return num.length > 0 });
var results = "";
var numMatchesFound = 0;
for (x = 0; x < a.length; x++) {
    for (y = 0; y < b.length; y++) {
        if (a[x] == b[y]) {
            numMatchesFound++;
            results += "<br>" + b[y];
        }
    }
}
results = "<br>Found " + numMatchesFound + " matches." + results;
document.getElementById("result").innerHTML = results;
}
</SCRIPT>

<META name="GENERATOR" content="MSHTML 10.00.9200.16798"></HEAD> 
<BODY>
<H1>Match finder</H1>
<P> Entries can be words, 
numbers, or whatever.</P>
 <H2>Paste a list of entries, one per line, in this 
box:</H2><TEXTAREA id="a" rows="10" cols="30"></TEXTAREA> <BR>
<H2>Paste another list of entries, one per line, in this box:</H2><TEXTAREA id="b" rows="10" cols="30"></TEXTAREA> 
<BR><BUTTON onclick="check()" type="button">Check for matches</BUTTON> <BR>
<DIV id="result"></DIV>
</BODY>
</HTML>

1 个答案:

答案 0 :(得分:0)

在&#34;控制台&#34;中查看&#34;开发人员工具&#34;标签:

对象不支持属性或方法&#39;过滤&#39; 文件:test.html,行:7,列:1

尽管据报道自IE9(http://www.w3schools.com/jsref/jsref_filter.asp)以及Microsoft描述如何使用它(https://msdn.microsoft.com/en-us/library/ff679973(v=vs.94).aspx)以来支持该功能,但由于某些原因这是不可用的。

谢天谢地jQuery =)

或尝试修改元标记。很确定你告诉IE假装它是IE5。我删除了你的meta标签,它运行得很好。