我的for循环内输出分叉失败

My for in loop output fork fails

本文关键字:分叉 失败 输出 for 循环 我的      更新时间:2023-09-26

我正在看这个"for in"教程,我不明白为什么我不能让循环来写aProperty值,而不仅仅是它的名称。http://www.tutorialspoint.com/cgi-bi...=javascript_15

我尝试过:document.write(navigator.aProperty);document.write(navigator++aProperty);以及其他各种形式,都失败了。

如果我只是编码document.write(navigator.onLine);为什么我不能让var"aProperty"作为document.write参数工作?

谢谢!

<script type="text/javascript">
<!--
var aProperty;
document.write("Navigator Object Properties<br /> ");
for (aProperty in navigator)
 {
document.write(aProperty);
document.write("<br />");
}
document.write("Exiting from the loop!");
//-->
</script>
</body>
</html>

aProperty实际上只是关键。要返回值,您需要向navigator索取。

将此添加到您的for中。。。环路中:

for (aProperty in navigator)
{
    document.write(navigator[aProperty]);
    document.write("<br />");
}