JavaScript两个常用的客户端输出方法
常用的两个客户端输出方法
document.write(str)
描述:在网页的<body>标记,输出str的内容。
document意思“文档”,就是整个网页了。
document是一个文档对象,代表整个网页。
write()是document对象的一个输出方法。
“.”小数点:通过小数点(.)来调用对象的方法。
str:表示要输出的内容。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>php.cn</title>
<script type="text/javascript">
//在<body>中输出一句话
document.write("欢迎来到php.cn");
</script>
</head>
<body>
</body>
</html>window.alert(str)
描述:在当前窗口中弹出一个警告对话框,str为对话框中显示的内容。
window代表当前浏览器窗口,window是一个窗口对象。
alert()方法:弹出一个对话框。
str:表示要输出的内容。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>php.cn</title>
<script type="text/javascript">
//打开网页时,弹出一个对话框
window.alert("欢迎来到php.cn");
</script>
</head>
<body>
</body>
</html>

Air张
问题解答: 1.继续学习点击右侧章节往下; 2.加不加分号都可以,分号就是结束当前语句; 3.document.write()和document.getElementById()不是一个概念;
7年前 添加回复 0