为什么此脚本中的警报不起作用?

-5 html javascript alert var

我希望将文档中给出的文本的一些信息转换为变量,并将它们插入警报进行验证,但警报不起作用.为什么会这样?

这是代码的一部分:

<head>
<script type="text/javascript">
window.onload = function() {

var enlaces = document.getElementsByTagName("a");
var numero = enlaces.length();
var dir = enlaces[numero-2].href;
var contador = 0;

for (var i = 0; i <= enlaces.length-1; i++) {
    if(enlaces[i].href = "http://prueba" || enlaces[i].href = "http://prueba/")
        contador++;
};

var parrafos = document.getElementsByTagName("p");
var enlacesTercerParrafo = parrafos[2].getElementsByTagName("a").length;

alert("El numero de enlaces es:");

}
</script>
</head>
Run Code Online (Sandbox Code Playgroud)

and*_*ndi 5

.length之后不应该有(); 它应该是这样的:

var numero = enlaces.length;
Run Code Online (Sandbox Code Playgroud)