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("执行代码 ...
随机推荐
- FIR数字信号滤波器
数字滤波器 在信号处理领域中,对于信号处理的实时性.快速性的要求越来越高.而在许多信息处理过程中,如对信号的过滤.检测.预测等,都要广泛地用到滤波器. 其中数字滤波器具有稳定性高.精度高.设计灵活.实 ...
- .NET4缓存过期策略摘录
以下是网上搜索的资料,仅供参考: 资料一:ASP.NET缓存中Cache过期的三种策略(转自51CTO) 我们在页面上添加三个按钮并双击按钮创建事件处理方法,三个按钮使用不同的过期策略添加ASP.NE ...
- windows下通过.bat运行java程序
在windows下运行Java项目,单独的jar可以使用,java -jar xxx.jar 运行,如果是一个zip包,里面包含了class文件和所依赖的jar的时候,可以使用 (也可以以看看这里): ...
- (转)C# Socket异步通信
本文转载自:http://www.cnblogs.com/llllll/archive/2009/05/13/1455703.html 服务器端 TCPServer 1.使用的通讯通道:socket ...
- phantomjs 安装和试用
准备学习casperjs, 发现官网上说 it’s an extremely useful companion to PhantomJS, 所以决定下把它下来试试.下载安装(win7)没什么可说的, ...
- python学习(十) 自带电池
10.1 模块 >>> import math >>> math.sin(0) 0.0 10.1.1 模块是程序 假设自己写的hello.py放在c:\python ...
- MOS管防止电源反接的原理
[导读] 一般可以使用在电源的正极串入一个二极管解决,不过,由于二极管有压降,会给电路造成不必要的损耗,尤其是电池供电场合,本来电池电压就3.7V,你就用二极管降了0.6V,使得电池使用时间大减. ...
- C#三层架构详细解剖
深入浅出C#三层架构(转) 本文用一个示例来介绍如何建设一个三层架构的项目,并说明项目中各个文件所处的层次与作用.写本文的目的,不是为了说明自己的这个方法有多对,而是希望给那些初学三层架构却不知从何入 ...
- python--open用法
open/文件操作f=open('/tmp/hello','w') #open(路径+文件名,读写模式) #读写模式:r只读,r+读写,w新建(会覆盖原有文件),a追加,b二进制文件.常用模式 如:' ...
- C#统计网站访问总人数和当前在线人数 Application
一.打开vitualstudio2010,新建一个网站,然后添加新项,新建一个login.aspx和index.aspx页面.再添加新项,选择全局应用程序类,该页面为Global.asax. 第一步: ...