window.document 对象
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript"> function getById(id)
{
//根据id查找 var aa = document.getElementById(id); aa.style.backgroundColor="#FFF"; alert(aa);
/* alert("innerHTML = " + aa.innerHTML);
alert("outerHTML" + aa.outerHTML);
alert("innerText" + aa.innerText); aa.innerText = "";*/ } function getByName(name)
{
//根据id查找
//var aa = document.getElementById(id); var aa = document.getElementsByName(name); alert(aa); if (aa.length > 0)
{
alert(aa[0].innerText);
} /*alert("innerHTML = " + aa.innerHTML);
alert("outerHTML" + aa.outerHTML);
alert("innerText" + aa.innerText); aa.innerText = "";*/
} function getByTagName(name)
{
var aa = document.getElementsByTagName(name); alert(aa); if (aa.length > 0)
{
for (var i = 0; i < aa.length; i++)
alert(aa[i].innerText);
} /*alert("innerHTML = " + aa.innerHTML);
alert("outerHTML" + aa.outerHTML);
alert("innerText" + aa.innerText); aa.innerText = "";*/
} function getByClassName(name)
{
var aa = document.getElementsByClassName(name); alert(aa); if (aa.length > 0)
{
for (var i = 0; i < aa.length; i++)
alert(aa[i].innerText);
} /*alert("innerHTML = " + aa.innerHTML);
alert("outerHTML" + aa.outerHTML);
alert("innerText" + aa.innerText); aa.innerText = "";*/
} function getByForm()
{
try
{
var aa = document.myForm.f6; alert(aa.value); aa.value = "新的内容"; aa.setAttribute("newvalue", "新属性值"); var bb = aa.getAttribute("daan") alert(bb); aa.removeAttribute("newvalue"); bb = aa.getAttribute("newvalue"); alert(bb);
}
catch(ex)
{
alert(ex);
}
} </script>
</head> <body> <div style="background-color:#F00; height:100px;" id="a" name="b" ><b>这是另一个元素</b></div>
<div class="c" id="ab"><b>这是一个元素</b></div> <form name="myForm" action="#" method="get" > <br /> <input id="f1" type="button" onclick='getById("a");' value="根据ID查找元素" /> <br /> <input id="f2" type="button" onclick='getByName("b");' value="根据Name查找元素" /> <br /> <input id="f3" type="button" onclick='getByTagName("div");' value="根据TagName查找元素" /> <br /> <input id="f4" type="button" onclick='getByClassName("c");' value="根据ClassName查找元素" /> <br />
<input id="f6" daan="1921年" type="text" width="30" value="内容" /> </form> <br /> <input id="f5" type="button" onclick='getByForm();' value="查找表单元素" /> </body>
</html>
window.document 对象的更多相关文章
- Window.document对象
1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docunme ...
- JavaScript的DOM操作。Window.document对象
间隔执行一段代码:window.setlnteval("需要执行的代码",间隔毫秒数) 例 : window.setlnteval("alert("你 ...
- Window.document对象 轮播练习
Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docun ...
- HTML Window.document对象
1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docunmen ...
- Window.document对象(1)
1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docunme ...
- JS中window.document对象
小知识点注:外面双引号,里面的双引号改为单引号: 在div里面行高设置和整个外面高度一样,才能用竖直居中,居中是行居中 文本框取出来 ...
- 1、Window.document对象
1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docunmen ...
- 3.26课·········window.document对象
1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docun ...
- 2016/2/22 1、Window.document对象
1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docunme ...
- DOM操作(Window.document对象)
间隔与延迟: 间隔一段代码: window.setInterval("代码",间隔执行秒数) 延迟一段时间后执行一段代码: window.setTimeout("执行代码 ...
随机推荐
- FPGA前世今生(三)
上期介绍了关于FPGA的IOB单元,这期我们介绍一下FPGA内部的其他资源,这些都是学好FPGA的基础.不管前世的沧桑,还是后世的风光,我们都要把我现在的时光,打好基础,学好FPGA. 大多数FPGA ...
- npm笔记和bower
生成package.json文件的方式就是dos下进入该文件夹,然后执行 npm init Bower简单点儿说就是通过nodejs直接下载GitHub上的js源码 首先你得有node,这里就不多做介 ...
- 概念与用法-cookie,session,auth (认证系统)
COOKIE 与 SESSION 概念 cookie不属于http协议范围,由于http协议无法保持状态,但实际情况,我们却又需要“保持状态”,因此cookie就是在这样一个场景下诞生. cookie ...
- oracle的sqlldr时插入新列和固定数据
ctl文件加入固定值 region CONSTANT '31', 加入默认时间 RECORD_DATE "sysdate" 最好数据也设置RECORD_DATE的默认值为sysda ...
- Python中的 set 与 深浅拷贝
字符串 join() 格式: "拼接的东西".join(可迭代对象) 可以加列表转换成字符串 lis = ['a','b','c','d'] s = "//" ...
- Java微信公众平台开发(十四)【番外篇】--微信web开发者工具使用
转自:http://www.cuiyongzhi.com/post/58.html 为帮助开发者更方便.更安全地开发和调试基于微信的网页,微信推出了 web 开发者工具.它是一个桌面应用,通过模拟微信 ...
- jenkins 学习记录1
主题 以前自己做些小玩意儿比如博客(http://blogv3.labofjet.com/)的时候,在远程服务器上的tomcat发布工程用的是目录的结构,而不是war.原因很简单.用目录结构的话每次只 ...
- PHP中file_exists()判断中文文件名无效的解决方法
php中判断文件是否存在我们会使用file_exists函数或is_file函数,但在使用file_exists时如果你文件名或路径是中文在uft8编码文档时是无效.本文就来解决此问题,下面我们一起来 ...
- C#使用ADO操作Excel
1 说明 把excel当成一个数据库,类似于Access数据库来操作. 2 源代码 2.1 Model层 /// <summary> /// 人员信息 /// </summary&g ...
- 【HDU4960】Another OCD Patient
题意 给出一个长度为n的整数序列.可以将一段连续的序列进行合并.合并的长度不同代价不同.问付出最少多少代价可以将这个序列变成一个对称的序列.n<=5000 分析 一看题感觉是个dp很好写啊.f[ ...