1、someNode.childNodes是一个对象,是类数组,利用Array.prototype.slice.call(someNode.childNodes);能将此对象转化为数组。这个方法可以将具有length属性的类数组转化为数组,比如:arguments
2、用js设置页面title属性:document.title
3、通过设置document.domain可以把子域名设置为宽松的域名,这样,同一个域名下就可以跨域了
4、调用document.getElementsByTagName('img'),可以获得一个类数组images,images.namedItem('haha')或者images['haha'],就可以获得name为haha的img元素了。
5、在写单选(type=radio)按钮时,name相同,id绑定不同的label。
6、var div = document.getElementById('myDiv'); 可以用‘点号’获取属性,也可以用getAttribute('hehe')获取属性,自定义属性不可以用‘点号’。只有在自定义特性值的情况下,才会使用getAttribute()方法。
7、setAttribute('id','someOtherId'); 设置属性。div.removeAttribute('class'); 删除属性。
8、someNode.replaceChild(newNode,someNode.firstChild);
someNode.removeChild(someNode.firstChild);
someNode.cloneNode(true);//连带着子节点一起拷贝
9、document.createElement('div') //新建节点
document.createTextNode('hello') //新建文本节点
如果在一个节点中包含两个文本节点,调用父节点的normalize(),就能合并了
10、一个文本节点,想分隔成两个文本节点,用splitText()方法,返回截取后余下的字符串,原文本节点变为前几个字符串。