JS顶级对象window
<script type="text/javascript">
var num = 100;
alert(num);
window.alert(window.num);
function f1() {
window.alert('哈哈哈');
}
window.f1();
//在js中声明的变量,方法都属于window,所以window是顶级对象
var num = 100;
alert(num);
window.alert(window.num);
function f1() {
window.alert('哈哈哈');
}
window.f1();
//在js中声明的变量,方法都属于window,所以window是顶级对象
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script type="text/javascript">
window.onload = function () {
//alert(window.fm.btn.value);//层级多的话使用不方便
alert(document.getElementById("btn").value);//推荐使用
}
</script>
</head>
<body>
<form action="/" method="post" id="fm">
<input type="button" name="name" value="HH" id="btn" />
</form>
</body>
</html>