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.不可奸淫.
随机推荐
- Oracle 的表备份的方法
1.直接备份(防止误操作后数据库表不能恢复) create table new_table as select * from old_table; 2.创建表头,然后插入列(繁琐的做法) create ...
- PyCharm 教程(四)显示行号
PyCharm 教程(四)显示行号 在PyCharm 里,显示行号有两种办法: 1,临时设置.右键单击行号处,选择 Show Line Numbers. 但是这种方法,只对一个文件有效,并且,重启Py ...
- VIM的姿势
http://blog.csdn.net/vincent_czz/article/details/7900670 http://bbs.feng.com/read-htm-tid-7435912.ht ...
- inpyt 按钮变透明 边框
变透明: .btn{width: 80px;height: 36px;margin-left: 22px;border: none;cursor: pointer;background: none;}
- Mono
mono (Novell公司开发的跨平台·NET运行环境) http://baike.baidu.com/link?url=iGl5T4-pmpJwB01mQxHq95bJcrCvR_JMNNfP0u ...
- RHEL-界面中文乱码问题
一.虚拟机里的rhel更换为中文简体后,中文字符变为小方块 二.解决方法: 安装中文支持的软件包 fonts-chinese-3.02-12.el5.noarch.rpm fonts-ISO8859- ...
- IdentityDbContext
Move the ApplicationUser definition to your DAL. Inherit your MyDbContext from IdentityDbContext< ...
- Working with Transactions (EF6 Onwards)
Data Developer Center > Learn > Entity Framework > Get Started > Working with Transactio ...
- Yii2 如何更好的在页面注入JavaScript
先添加一个widgets <?php /** * User: yiqing * Date: 14-9-15 * Time: 下午12:09 */ namespace common\widgets ...
- [转]Sql按年份.月份.每天统计数量
1.每年 select year(ordertime) 年, sum(Total) 合计 from 表 group by year(ordertime) 2.每月 select year(ordert ...