我在谷歌瀏覽器中測試了下面的代碼,但是警報顯示爲什麼? (我把它從http://msdn.microsoft.com/en-us/magazine/cc163419.aspx)爲什麼我的javascript警報不顯示
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
</head>
<body>
<script type="text/javascript">
function filter(pred, arr) {
var len = arr.length;
var filtered = []; // shorter version of new Array();
// iterate through every element in the array...
for (var i = 0; i < len; i++) {
var val = arr[i];
// if the element satisfies the predicate let it through
if (pred(val)) {
filtered.push(val);
}
}
return filtered;
}
var someRandomNumbers = [12, 32, 1, 3, 2, 2, 234, 236, 632, 7, 8];
var numbersGreaterThan100 = filter(function (x) {
return (x > 100) ? true : false;
}, someRandomNumbers);
// displays 234, 236, 632
alert(numbersGreaterThan100);
</script>
</body>
</html>
你的標題和質疑的身體衝突。請澄清。 – Cameron 2012-01-31 17:56:49
可能是你的腳本出錯 - 查看Chrome控制檯的錯誤 – 2012-01-31 17:56:49
是否嘗試用「<」替換「<」,例如:for(var i = 0; i
Akhil
2012-01-31 17:57:04