求教,为什么不把函数放在function里就无法出来正确结果?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>GET Name</title>
<script>
var pick=document.getElementsByName("myt");
alert(pick.length);
</script>
</head>
<body>
<input name="myt" type="text" value="1">
<input name="myt" type="text" value="2">
<input name="myt" type="text" value="3">
<input name="myt" type="text" value="4">
<input name="myt" type="text" value="5">
<input name="myt" type="text" value="6">
</body>
</html>
求教,为什么必须要把这段代码放在function里去再用onclick去执行呢,这样出来结果一直是0,放在function里再加个onclick的按钮才能出来结果为6