javascript document对象 第21节
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript document对象 第21节,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5081字,纯文字阅读大概需要8分钟。
内容图文
<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.
原文:http://www.cnblogs.com/feilongblog/p/4744907.html
内容总结
以上是互联网集市为您收集整理的javascript document对象 第21节全部内容,希望文章能够帮你解决javascript document对象 第21节所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。