4.8.2.JSDOM对象控制HTML元素详解
1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>DOM对象控制HTML</title>
</head>
<body>
<p name="pn">hello</p>
<p name="pn">hello</p>
<p name="pn">hello</p>
<a id="aid" title="得到了a标签的属性">hello</a>
<a id="aid2">aid2</a>
<ul><li>1</li><li>2</li><li>3</li></ul>
<div id="div">
<p id="pid">div的P元素</p>
</div>
<script>
function getName() {
var count = document.getElementsByName("pn");
alert(count.length);
var p = count[2];
p.innerHTML = "World";
}
function getAttr() {
var anode = document.getElementById("aid");
var attr = anode.getAttribute("id");
alert(attr);
}
function setAttr() {
var anode = document.getElementById("aid2");
anode.setAttribute("title", "动态设置a的title属性");
var attr = anode.getAttribute("title");
alert(attr);
}
function getChildNode() {
var childnode = document.getElementsByTagName("ul")[0].childNodes;
alert(childnode.length);
alert(childnode[0].nodeType)
}
function getParentNode() {
var div = document.getElementById("pid");
alert(div.parentNode.nodeName);
}
function createNode() {
var body = document.body;
var input = document.createElement("input");
input.type = "button";
input.value = "按钮";
body.appendChild(input);
}
function addNode() {
var div = document.getElementById("div");
var node = document.getElementById("pid");
var newnode = document.createElement("p");
newnode.innerHTML = "动态添加体格p元素";
div.insertBefore(newnode, node);
}
function removeNode() {
var div = document.getElementById("div");
var p = div.removeChild(div.childNodes[1]);
}
function getSize() {
var width = document.body.offsetWidth || document.documentElement.offsetWidth;
var height = document.body.offsetHeight;
alert(width + " " + height);
}
getSize();
</script>
</body>
</html>
4.8.2.JSDOM对象控制HTML元素详解的更多相关文章
- JS DOM对象控制HTML元素详解
JS DOM对象控制HTML元素详解 方法: getElementsByName() 获取name getElementsByTagName() 获取元素 getAttribute() 获取元素 ...
- javascript - DOM对象控制HTML元素详解
1.方法 getElementsByName() -- 获取name getElementByTagName() -- 获取 getAttribute() --获取元素属性 se ...
- web前端学习(四)JavaScript学习笔记部分(7)-- JavaScript DOM对象控制HTML元素详解
1.方法 getElementsByName() 获取name 可以获取一个数组类型数据(参数加引号) getElementsByTagName() 获取元素 getAttribute() 获取元 ...
- html5中output元素详解
html5中output元素详解 一.总结 一句话总结: output元素是HTML5新增的元素,用来设置不同数据的输出,没什么大用,了解即可 <form action="L3_01. ...
- 史上最全web.xml配置文件元素详解
一.web.xml配置文件常用元素及其意义预览 <web-app> <!--定义了WEB应用的名字--> <display-name></display-na ...
- asp.net中C#对象与方法 属性详解
C#对象与方法 一.相关概念: 1.对象:现实世界中的实体 2. 类:具有相似属性和方法的对象的集合 3.面向对象程序设计的特点:封装 继承 多态 二.类的定义与语法 1.定义类: 修饰符 类名称 ...
- java对象池commons-pool-1.6详解(一)
自己的项目中用到了 对象池 commons-pool: package com.sankuai.qcs.regulation.protocol.client; import com.dianping. ...
- web.xml配置文件元素详解
一.web.xml配置文件常用元素及其意义 1 <web-app> 2 3 <!--定义了WEB应用的名字--> 4 <display-name></disp ...
- JavaScript对象的property属性详解
JavaScript对象的property属性详解:https://www.jb51.net/article/48594.htm JS原型与原型链终极详解_proto_.prototype及const ...
随机推荐
- 基于G6画个xmind出来
公司产品因为业务发展,出现了一个新的需求:需要去实现知识库的层级知识展示,展示效果通过树图来实现,具体的展示形式可见下图: 其中有几个需要注意点: 节点上的详情icon可以点击,点击展开关闭详情 节点 ...
- input输入框type设置为number,maxlength无效
一个小细节,以前很少注意,直到最近做的一个项目,当我把一个输入数字的input框的类型设置为number时,input框还是可以无限输入,设置maxlengh=10就不起作用了.然后我就去百度了一下, ...
- 在工业派上使用opencv库的记录
1.在工业派linux操作系统环境下,调用OpenCV库,用python写了第一个查看图片的程序 注意:要进入工业派的terminal 参考:https://www.cnblogs.com/magic ...
- python下matplotlib的subplot的多图显示位置的问题
1.说明 1.1 多图: 221,222 212 ------------附最后讲解,这下更清楚了吧,取个名字:颠倒一下--- 1.2 多图 211 223,224 ------------附最后讲解 ...
- linux磁盘管理2-raid,lvm
raid 多个磁盘合成一个“阵列”来提供更好的性能.冗余,或者两者都提供 提高IO能力 磁盘并行读写 提高耐用性 磁盘冗余来实现 级别:多块磁盘组织在一起的工作方式有所不同 RAID实现的方式 外接式 ...
- base64,base32bit加密解密
import base64 str='admin' str=str.encode('utf-8') #加密 bs64=base64.b64encode(str) #解密 debs64=base64.b ...
- RDLC 表达式设置精度
=IIf(RTrim(Parameters!u_currency.Value)="VND","F0","F2")
- 2020.02.28 Linux 命令
Cat 语法格式 cat [-AbeEnstTuv] [--help] [--version] fileName 参数说明: -n 或 --number:由 1 开始对所有输出的行数编号. -b ...
- ipmitool命令
1.remote access control powerIpmitool -I lanplus -H 192.168.0.10 -U username -P Password chassis pow ...
- XPath简介
参考视频: https://www.bilibili.com/video/av49809274/?p=22 一,什么是XPATH? xpath(xml path language)是一门在xml和 ...