一、document的属性
document是window对象的一个属性,因为使用window对象成员的时候可以省略window.,所以一般直接写document 。
二、document的方法:
1、write:向文档中写入内容。writeln,和write差不多,只不过最后添加一个回车。
<input type="button" value="点击" onclick="document.write('<font color=red>你好</font>')" />
(1)在onclick等事件中写的代码会冲掉页面中的内容,只有在页面加载过程中write才会与原有内容融合在一起。
<script type="text/javascript">
document.write('<font color=red>你好</font>');
</script>
<script type="text/javascript">
document.write("<font color=red>红色呀</font>");
</script>
(2)write经常在广告代码、整合资源代码中被使用:
① 广告代码的例子:在http://heima8.com/注册一个账户(测试用 账户名:itcast0710 密码:123456),申请一个广告代码,然后放到页面中。
② 整合资源的例子:百度新闻 http://ne