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有限状态机
状态机几乎可以实现一切时序电路. 有限状态机(FiniteStateMachine, FSM),根据状态机的输出是否与输入有关,可分为Moore型状态机和Mealy型状态机.Moore型状态机输出仅仅 ...
- java数字游戏基础篇
题目: 1.100以内,程序先产生一个随机数,然后用户从控制台输入数字,猜是大了还是小了,第7次时 输出 “您太笨了,答案是”+x 思路:1.随机数,所以用到random 2.用户从键盘输入 ,则用到 ...
- easyui tree 加载展开全部节点
$(function () { $('#tbClientListCont').tree({ checkbox: false, url: '/ashx/Client/tbClientList.ashx? ...
- angular 本地存储
localStorage四种方法: localStorage.getItem(key):获取指定key本地存储的值localStorage.setItem(key,value):将value存储到ke ...
- unicode gbk 转换函数
typedef unsigned short WCHAR; //字库信息结构体定义 //用来保存字库基本信息,地址,大小等 __packed typedef struct { u8 fontok; / ...
- mybatis~动态SQL(1)
动态SQL MyBatis还有一个方便的功能就是动态SQL,可以根据条件智能生成SQL语句.这里的例子全部来自MyBatis文档. if标签 下面这个例子使用了MyBatis的if元素,在标题不为空的 ...
- centos 系统使用verdaccio搭建npm私库
.安装nodejs yum install -y nodejs 2.安装verdaccio npm install -g verdaccio --unsafe-perm 3.配置 a.修改配置文件 c ...
- spring-boot多环境配置文件
spring-boot多环境配置文件 目录 配置 多环境配置文件名称要遵循格式 application-{profile}.yml application.yml spring: profiles: ...
- oracle 函数中,一定要注意出现空记录和多条记录的处理方法
今天折腾了3个小时,为一个以前不知道的oracle函数机制: 在sql查询中,如果一个查询未能获取记录,oracle不会报错 如select aa from bb where 1=2; 但在oracl ...
- Storm集群部署及单词技术
1. 集群部署的基本流程 集群部署的流程:下载安装包.解压安装包.修改配置文件.分发安装包.启动集群 注意: 所有的集群上都需要配置hosts vi /etc/hosts 192.168.239.1 ...