javascript基础:document对象

document对象包含一些属性,如:domain,referrer。

下面代码遍历了document中包含的所有对象,另外,打开一个新的窗口,在新的窗口中用document对象的open方法,打开新的文档,在文档里输入了标签,最后用close方法关闭文档。

通过document.getElementById document.getElementsByName可以找到指定id或者属性名称的标签。

代码:

<!DOCTYPE HTML>
<HTML>
 <HEAD>
  <TITLE id="title1"> New Document </TITLE>
  <META CHARSET="gb2312">

	<script language="javascript">
		function openWinDoc()
		{
			myWin = window.open("","","width=500,height=500");

			myWin.document.open("text/html","replace");
			myWin.document.write("<html><head><title>新文档</title></head>");
			myWin.document.write("<body>这是一个新的文档</body></html>");
			myWin.document.close();
		}

		function getId()
		{
			var c = document.getElementById("title1").tagName;
			alert("窗口标题:" + c);
		}

		function getName()
		{
			var c = document.getElementsByName("blist").length;
			alert("按钮个数:" + c);
		}
	</script>
 </HEAD>

 <BODY>

	<input type="button" value="打开新窗口-文档" οnclick="openWinDoc()"><br><hr>
	<input type="button" name="blist" value="用id获取窗口标题的标签" οnclick="getId()"><br><hr>
	<input type="button" name="blist" value="用name获取button属性名为blist的按钮数量" οnclick="getName()"><br><hr>

  	<script language="javascript">		
		/*
		domain: 服务器的网域名
		referrer: 连接这个网页的url
		title: 标题
		url:网页url
		*/
		for(o in window.document)
			if(typeof(window.document[o]) != "unknown" )
				window.document.write(o + ":->" + window.document[o] + "<br>");
			else
				window.document.write(o + ":-><br>");

	</script>
 </BODY>
</HTML>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值