javascript document对象 第21节

<html>
<head>
	<title>DOM对象</title>
	<style type="text/css">
	  table {
                   border:1px solid green;
				   border-collapse:collapse;
				   width:300px;
	  }
	  td {
              padding:5px;
              border:1px solid green;
			  font-size:16px;
			  text-align:center;
	  }
	  table#tab {
                  border:1px solid green;
				   border-collapse:collapse;
				   width:128px;
	  }
	  #tab td {

              border:1px solid green;
			  padding:1px;
	  }
	  #tab td img {
          border:0;
	  }
	</style>
	<script type="text/javascript">
	       function showMsg(id) {
                   var val = document.getElementById(id);//节点
				   if(val.nodeName == "SPAN") {
                         alert(val.innerHTML);// 文本使用innerHTML
						 val.innerHTML = "oracle";//可以取值 赋值
				   } else {
                        alert(val.value);//文本框使用value属性取值
						val.value="李四";
				   }

		   }
		   function checkAll(sta) {
                // alert(sta);
				var arr = document.getElementsByName("loves");//数组
				//alert(arr.length);
				//设置状态
				for(var i = 0; i < arr.length; i++ ) {
                     arr[i].checked = sta;
				}
		   }

	</script>
	</head>
	<body>
	<div>DOM对象</div>
		1.document对象  getElementById()  getElementsByName()<br/>
			<script type="text/javascript">
			     /*
			      document.open();//打开流
				  document.close();
				  */
			     document.write("document.body : ", document.body.nodeName , "<br/>");
				  document.write("document.cookie : ", document.cookie , "<br/>");
				  document.write("document.domain : ", document.domain , "<br/>");
				  document.write("document.lastModified : ", document.lastModified , "<br/>");
				  document.write("document.referrer : ", document.referrer , "<br/>");
				  document.write("document.title : ", document.title , "<br/>");
				  document.write("document.URL : ", document.URL , "<br/>");
				/*
				  document.writeln("document.URL : " );
				  document.write("document.URL : " );
                  */
			</script>
			<table>
			<tr><td><span id="show">javascript</span></td></tr>
			<tr><td><input type="text" name="username" id="username"/></td></tr>
			<tr><td><input type="button" value="span" onclick="showMsg(‘show‘)"/>
			<input type="button" value="文本框" onclick="showMsg(‘username‘)"/></td></tr>

            <tr><td><input type="checkbox" name="control"  onclick="checkAll(this.checked)"/>全选/全不选</td></tr>
			<tr><td>

			<input type="checkbox" name="loves" value="足球"/>足球
			<input type="checkbox" name="loves" value="上网"/>上网
			<input type="checkbox" name="loves" value="旅游"/>旅游
			<input type="checkbox" name="loves" value="阅读"/>阅读

			</td></tr>
			</table><br/>

		2.document对象  getElementsByTagName()<br/>

			<script type="text/javascript">
			      function randomImg() {
						var tab = document.getElementById("tab");//获取表格
						//通过标记名获取img
						var imgs = tab.getElementsByTagName("img");
						//alert(imgs.length);
						for(var i = 0; i < imgs.length; i++ ) {
							imgs[i].src = "ICONS/0" + ( Math.round( Math.random() * 84) + 11) + ".BMP"

						}

				  }
			</script>
			<table id="tab">
			<tr>
			<td><img src="ICONS/011.BMP"/></td>
			<td><img src="ICONS/011.BMP"/></td>
			<td><img src="ICONS/011.BMP"/></td>
			<td><img src="ICONS/011.BMP"/></td>
			</tr>
			<tr>
			<td><img src="ICONS/011.BMP"/></td>
			<td><img src="ICONS/011.BMP"/></td>
			<td><img src="ICONS/011.BMP"/></td>
			<td><img src="ICONS/011.BMP"/></td>
			</tr>
			<tr>
			<td><img src="ICONS/011.BMP"/></td>
			<td><img src="ICONS/011.BMP"/></td>
			<td><img src="ICONS/011.BMP"/></td>
			<td><img src="ICONS/011.BMP"/></td>
			</tr>
			<tr>
			<td><img src="ICONS/011.BMP"/></td>
			<td><img src="ICONS/011.BMP"/></td>
			<td><img src="ICONS/011.BMP"/></td>
			<td><img src="ICONS/011.BMP"/></td>
			</tr>

			</td></tr>
			</table><br/>
         <input type="button" value="打散" onclick="randomImg()"/><br/>

		3.集合<br/>
		    <a href="http://www.baidu.com">百度</a><br/>
			<a href="http://www.sina.com">新浪</a><br/>
			<a href="http://www.taobao.com">淘宝</a><br/>
			<form><input type="button" value="提交" /></form>
			<form action="DOM对象操作.htm">
			<input type="button" value="提交" />
			</form>
			<img src="p1.jpg"/><br/>
			<img src="p2.jpg"/><br/>
			<script type="text/javascript">
			   document.write("document.links[1] .href : ", document.links[1] .href, "<br/>");
			   document.write("document.forms[1] .action : ", document.forms[1] .action, "<br/>");
			   document.write("document.images[17] .src : ", document.images[17] .src, "<br/>");

			   function replaceCon() {
						document.links[1] .href = "http://www.163.com";
					   document.forms[1] .action = "内置对象.htm";
					   document.images[17] .src = "开发语言排行.jpg";
					   alert(document.forms[1] .action);

				  }
			</script>

         <input type="button" value="替换" onclick="replaceCon()" />

</body>
</html>

rs:

2.

时间: 2024-08-07 04:12:54

javascript document对象 第21节的相关文章

JavaScript - document对象属性和方法

document对象的属性和方法 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>test10.html</title> <script type="text/javascript"> //document对象的属性 /*alert(document.referrer); a

JavaScript document 对象

1.document属性 cookie -- 用户cookie title -- 当前页面title标签中定义的文字 URL -- 当前页面的URL document代表HTML文档的内容,因此可以通过它表示文档中加载的一些元素,这些元素全部通过集合访问. anchors -- 文档中所有锚(a name="aname")的集合 applets -- 文档中所有applet标签表示的内容的集合 embeds -- 文档中所有embed标签表示的内容的集合 forms -- 文档中所有f

学习总结之javaScript document对象详解

Document对象内容集合 document 文挡对象 - JavaScript脚本语言描述———————————————————————注:页面上元素name属性和JavaScript引用的名称必须一致包括大小写否则会提示你一个错误信息 “引用的元素为空或者不是对象\\\\\”——————————————————————— 对象属性document.title //设置文档标题等价于HTML的title标签document.bgColor //设置页面背景色document.fgColor

javascript DOM对象 第18节

<html> <head> <title>DOM对象</title> </head><body><div >DOM对象</div> 1.DOM节点</br> <script type="text/javascript"> var root = document.documentElement; // var oHead = root.firstChild; //var

javaScript document对象详解

Document对象内容集合 document 文挡对象 - JavaScript脚本语言描述———————————————————————注:页面上元素name属性和JavaScript引用的名称必须一致包括大小写否则会提示你一个错误信息 “引用的元素为空或者不是对象\\\\\”——————————————————————— 对象属性document.title //设置文档标题等价于HTML的title标签document.bgColor //设置页面背景色document.fgColor

JavaScript document对象

document对象 1.document对象是window对象的子对象,可直接使用,多用于获取HTML页面元素 2.document对象属性 a) alinkColor活动链接颜色 b) linkColor文本链接颜色 c) vlinkColor用户已观察过文档链接的文本颜色 d) cookie存储于客户端的cookie信息 i.是某些web站点将用户的某些信息存储于客户硬盘中的一些小小的文本文件 ii.cookie可以记录用户的用户名.密码.浏览过的网页.停留的时间等,方便用户再次操作 ii

javascript DOM对象 第19节

<html> <head> <title>DOM对象</title> <script type="text/javascript"> function $(id) { return document.getElementById(id); } function insertText() { var val = window.prompt("请输入",""); //alert(val);

DOM中document对象的常用属性方法总结

提要: 每个载入浏览器的 HTML 文档都会成为 Document 对象. Document 对象使我们可以从脚本中对 HTML 页面中的所有元素进行访问 1.常见对象属性 document.title                 //设置文档标题等价于HTML的<title>标签document.bgColor               //设置页面背景色document.fgColor               //设置前景色(文本颜色)document.linkColor    

【温故而知新-Javascript】使用 Document 对象

Document 对象时通往DOM功能的入口,它向你提供了当前文档的信息,以及一组可供探索.导航.搜索或操作结构与内容的功能. 我们通过全局变量document访问Document对象,它是浏览器为我们创建的关键对象之一.Document对象提供了文档的整体信息,并让你能够访问模型里的各个对象.简单示例如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>