2016年11月2日--Window.document对象
一、找到元素:
docunment.getElementById("id"); 根据id找,最多找一个;
var a =docunment.getElementById("id"); 将找到的元素放在变量中;
docunment.getElementsByName("name"); 根据name找,找出来的是数组;
docunment.getElementsByTagName("name"); 根据标签名找,找出来的是数组;
docunment.getElementsByClassName("name") 根据classname找,找出来的是数组;
二、操作内容:
1. 非表单元素:
1)获取内容:
alert(a.innerHTML); 标签里的html代码和文字都获取了,标签里面的所有内容。
alert(a.innerText); 只取里面的文字
alert(a.outerHTML); 包括标签本身的内容(简单了解)
2)设置内容:
a.innerHTML = "<font color=red >hello world </font>";
a.innerText会将赋的东西原样呈现
清空内容:赋值个空字符串
2. 表单元素:
1)获取内容,有两种获取方式:
var t = document.f1.t1; form表单ID为f1里面的ID为t1的input;
var t = document.getElementById("id"); 直接用ID获取。
alert(t.value); 获取input中的value值;
alert(t.innerHTML); 获取<textarea> 这里的值 </textarea>;
2)设置内容: t.value="内容改变";
3. 一个小知识点:
<a href="http://www.baidu.com" onclick ="return false">转向百度</a> ;
加了return flase则不会跳转,默认是return true会跳转。按钮也一样,如果按钮中设置return flase 则不会进行提交,利用这个可以对提交跳转进行控制。
三、操作属性
首先利用元素的ID找到该元素,存于一个变量中:
var a = document.getElementById("id");
然后可以对该元素的属性进行操作:
a.setAttribute("属性名","属性值"); 设置一个属性,添加或更改都可以;
a.getAttribute("属性名"); 获取属性的值;
a.removeAttribute("属性名"); 移除一个属性。
四、操作样式
首先利用元素的ID找到该元素,存于一个变量中:
var a = document.getElementById("id");
然后可以对该元素的属性进行操作:
a.style="" ;操作此ID样式的属性。
样式为CSS中的样式,所有的样式都可以用代码进行操作。
document.body.style.backgroundColor="颜色"; 整个窗口的背景色。
操作样式的class:a.className="样式表中的classname" 操作一批样式
2016年11月2日--Window.document对象的更多相关文章
- 2016年11月3日--Window.document对象
五.相关元素操作: var a = document.getElementById("id");找到a: var b = a.nextSibling,找a的下一个同辈元素,注意包含 ...
- 2016年11月30日 星期三 --出埃及记 Exodus 20:21
2016年11月30日 星期三 --出埃及记 Exodus 20:21 The people remained at a distance, while Moses approached the th ...
- 2016年11月29日 星期二 --出埃及记 Exodus 20:20
2016年11月29日 星期二 --出埃及记 Exodus 20:20 Moses said to the people, "Do not be afraid. God has come t ...
- 2016年11月28日 星期一 --出埃及记 Exodus 20:19
2016年11月28日 星期一 --出埃及记 Exodus 20:19 and said to Moses, "Speak to us yourself and we will listen ...
- 2016年11月27日 星期日 --出埃及记 Exodus 20:18
2016年11月27日 星期日 --出埃及记 Exodus 20:18 When the people saw the thunder and lightning and heard the trum ...
- 2016年11月26日 星期六 --出埃及记 Exodus 20:17
2016年11月26日 星期六 --出埃及记 Exodus 20:17 "You shall not covet your neighbor's house. You shall not c ...
- 2016年11月25日 星期五 --出埃及记 Exodus 20:16
2016年11月25日 星期五 --出埃及记 Exodus 20:16 "You shall not give false testimony against your neighbor.不 ...
- 2016年11月24日 星期四 --出埃及记 Exodus 20:15
2016年11月24日 星期四 --出埃及记 Exodus 20:15 "You shall not steal.不可偷盗.
- 2016年11月23日 星期三 --出埃及记 Exodus 20:14
2016年11月23日 星期三 --出埃及记 Exodus 20:14 "You shall not commit adultery.不可奸淫.
随机推荐
- linux常用快捷键
linux常用快捷键:ctrl+c 强制终止当前命令ctrl+l 清屏ctrl+a 光标移动到命令行首ctrl+e 光标移动到命令行尾ctrl+u 从光标合所在的位置删除到行首ctrl+z 把命令放到 ...
- 第2章 两种调用JS的方法——在HTML中使用JavaScript
一. <script>标记 第一种方法是把 <sript></script>直接放到head和script两个标记之间(title下面,</head>上 ...
- HTML 个人资料框
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Rendering Paths
渲染路径 Rendering Paths http://game.ceeger.com/Manual/RenderingPaths.html 延迟光照渲染路径的细节 Deferred Lighting ...
- 创建为ClickOnce清单签名的.pfx格式数字证书
------ 第一步 创建 X.509 证书 ------makecert.exe为证书创建工具.证书创建工具生成仅用于测试目的的 X.509 证书.它创建用于数字签名的公钥和私钥对,并将其存储在证书 ...
- Create new tool for CSV
CsvFileStream.cs public class CsvFileStream { TextReader stream; bool EOS = false; bool EOL = false; ...
- jexus jws 安装
cd /tmp wget linuxdot.net/down/jexus--x64.tar.gz tar -zxvf jexus--x64.tar.gz mv jexus /usr rm -rf /t ...
- SCWS分词扩展在WINDOWS下的安装方法
安装之前先确认您是否拥有主机的安装权限,否则无法进行安装,安装步骤如下: 1. 根据您当前用的 PHP 版本,下载相应已编译好的 php_scws.dll 扩展库. 目前支持以下版本 [PHP-4 ...
- iOS- storyboard this class is not key value coding-compliant for the key xxx
如图: 在使用storyboard的时候出现此问题,主要是因为给storybroad中的view拖线的时候,有时不小心线拖错了,或者再次拖线导致代码中控件的名字与之前拖线时定义的名字不同导致的. 解决 ...
- 今天是JQ 的slideUp 和 slideDown 的点击事件
先贴代码,再讲详细事件 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> & ...