<!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 对象的更多相关文章

  1. Window.document对象

    1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:     var a =docunme ...

  2. JavaScript的DOM操作。Window.document对象

    间隔执行一段代码:window.setlnteval("需要执行的代码",间隔毫秒数) 例 :      window.setlnteval("alert("你 ...

  3. Window.document对象 轮播练习

    Window.document对象 一.找到元素:     docunment.getElementById("id"):根据id找,最多找一个:     var a =docun ...

  4. HTML Window.document对象

    1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:    var a =docunmen ...

  5. Window.document对象(1)

    1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:     var a =docunme ...

  6. JS中window.document对象

    小知识点注:外面双引号,里面的双引号改为单引号:                  在div里面行高设置和整个外面高度一样,才能用竖直居中,居中是行居中                  文本框取出来 ...

  7. 1、Window.document对象

    1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:    var a =docunmen ...

  8. 3.26课·········window.document对象

    1.Window.document对象 一.找到元素:    docunment.getElementById("id"):根据id找,最多找一个:    var a =docun ...

  9. 2016/2/22 1、Window.document对象

    1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:     var a =docunme ...

  10. DOM操作(Window.document对象)

    间隔与延迟: 间隔一段代码: window.setInterval("代码",间隔执行秒数) 延迟一段时间后执行一段代码: window.setTimeout("执行代码 ...

随机推荐

  1. ONVIF、RTSP/RTP、FFMPEG的开发实录

    前言 本文从零基础一步步实现ONVIF协议.RTSP/RTP协议获取IPC实时视频流.FFMPEG解码.开发环境为WIN7 32位 + VS2010. 最终成功获取浩云.海康.大华的IPC实时视频流. ...

  2. 类的特殊成员方法,类的起源type, metaclass

    1.__doc__表示类的描述信息 2. __module__ 和  __class__  __module__ 表示当前操作的对象在那个模块 __class__     表示当前操作的对象的类是什么 ...

  3. PL/SQL 训练02--集合数组

    1. 请列举关联数组.嵌套表.VARRAY三种集合类型的区别区别:1 关联数组只能在plsql中使用,嵌套表,varray可用于sql中,数据库表中的列2 嵌套表,varray必须在使用的时候初始化, ...

  4. StarkSoft题库管理系统

    一.功能介绍    1.自定义试题库管理系统目录.难易程度,题型,知识库等.    2.试题录入.    3.强大的试题编辑功能,并与通常应用编辑工具有共通.    4.灵活的试卷构造功能,用户可自定 ...

  5. 使用原生js创建自定义标签

    使用原生js创建自定义标签 效果图 代码 <!DOCTYPE html> <html lang="en"> <head> <meta ch ...

  6. java成神之——java常识

    java常识 简单DOS命令 java基础名词 java编译和运行流程 Eclipse常用快捷键 Eclipse相关操作 java基本数据类型 java基本数据类型转换 java常用运算符 java流 ...

  7. Windows环境下使用.bat安装和卸载服务

    一.Windows环境下使用.bat安装和卸载服务 win7环境 例子中“”Valwell.Dms.HttpService.exe“”为服务程序名称 安装服务 %SystemRoot%\Microso ...

  8. 清除stoped impdp/expdp job的方法

    stoped impdp/expdp job会在dba_datapump_jobs中留下一条记录,显示为not running. 清除stopped job分两种情况: 1) job能够attach ...

  9. EditText中onEditorAction监听事件执行两次

    Android的EditText通过setOnEditorActionListener给文本编辑框设置监听事件,但是在其处理方法onEditorAction中的逻辑在每次回车后都触发了两次, 原来是在 ...

  10. 优于jdbc的mybatis框架入门

    1.什么是mybatis? MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架. MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设置以及对结果集的检索. MyB ...