JS属性修改

document.getElementById('p1').style.visibility='visible'

document.getElementById('p1').style.visibility='hidden'

document.getElementById("p1").style.color="blue"

document.getElementById("p1").style.fontFamily="Arial"

document.getElementById("p1").style.fontSize="larger"

onload 事件:加载时页面触发

onunload 事件:离开页面触发

onclick 事件:点击元素触发

onchange 事件:改变输入触发

onmouseover 事件:光标覆盖触发

onmouseout 事件:光标移除触发

onmousedown 事件:点击鼠标触发

onmouseup 事件:松开鼠标触发

onfocus 事件:聚焦光标时触发

 

创建元素createElement()、添加子元素x.appendChild()

var para = document.createElement("p");

var node = document.createTextNode("这是一个新的段落。");

para.appendChild(node);

 

在child元素前插入para元素,element.insertBefore(para,child)

var para = document.createElement("p");

var node = document.createTextNode("这是一个新的段落。");

para.appendChild(node);

var element = document.getElementById("div1");

var child = document.getElementById("p1");

element.insertBefore(para, child);

 

 

移除页面子节点元素:x.removeChild(child)

移除元素x父节点下的其他元素y:x.parentNode.removeChild(y)

 

以节点para替换parent的子节点元素child

parent.replaceChild(para, child);

 

 

HTMLCollection 元素可以通过 name,id 或索引来获取。

NodeList 只能通过索引来获取。

 

串联数组:str1.concat(str2,str3)

分割数组:array1.join(',')

分割字符串:Str1.split(',')

删除数组第一个元素:str1.shift()

在数组开头加入元素:str1.unshift()

删除数组最后一个元素:str1.pop()

数组最后加入元素:str1.push()

从一个数组中选择元素:str1.slice(1,3)

将一个数组中的元素的顺序反转排序:str1.reverse()

在数组的指定位置添加一个元素 :str1.splice()---

数字排序(按数字顺序降序)- sort():

---str1.sort(function(a,b){return a-b}) 顺序

---str2.sort(function(a,b){return b-a}) 倒序

 

转载于:https://www.cnblogs.com/Snail-yellow/p/10280429.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值