|
1 | | -这是一个编辑常用代码的项目,用来搞定最基础的代码格式 |
| 1 | +这是一个编辑常用代码的项目,用来搞定最基础的代码格式. |
| 2 | +其中包括如下函数的使用方法: |
| 3 | + |
| 4 | +document.getElementById() |
| 5 | +document.getElementsByTagName() |
| 6 | +document.getElementByClassName() |
| 7 | +object.getAttribute(attribute) |
| 8 | +object.setAttribute(attribute,value) |
| 9 | +document.createElement(nodeName) |
| 10 | +document.createTextNode(text) |
| 11 | +parent.appendChild(child) |
| 12 | +parentElement.insertBefore(newElement,targetElement) |
| 13 | +自定义insertAfter() |
| 14 | +function insertAfter(newElement,targetElement){ |
| 15 | + var parent = targetElement.parentNode; |
| 16 | + if(parent.lastChild == targetElement){ |
| 17 | + parent.appendChild(newElement); |
| 18 | + }else{ |
| 19 | + parent.insertBefore(newElement,targetElement.nextSibling); |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +window.open(url,name,features) |
| 25 | +该方法中url为新创建浏览器窗口的url |
| 26 | +name为新创建浏览器窗口的名字 用来与原窗口通讯 |
| 27 | +features可以传入一个字符串 包含各项参数 |
| 28 | + |
| 29 | +根据该方法可以封装一个用于弹出新窗口的简洁方法 |
| 30 | +function popUp(winURL){ |
| 31 | + window.open(winURL,"popup","width=320,height=480"); |
| 32 | +} |
| 33 | + |
| 34 | +封装加入加载清单的方法: |
| 35 | +function addLoadEvent(func){ |
| 36 | + var oldonload = window.onload; |
| 37 | + if(typeof window.onload != 'function'){ |
| 38 | + window.onload = func; |
| 39 | + }else{ |
| 40 | + window.onload = function(){ |
| 41 | + oldonload(); |
| 42 | + func(); |
| 43 | + } |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +包含如下属性的使用方法: |
| 48 | + |
| 49 | +element.childNodes |
| 50 | +node.nodeType |
| 51 | +node.nodeValue #内容 |
| 52 | +node.firstChild |
| 53 | +node.lastChild |
| 54 | +node.childNodes |
| 55 | +object.innerHTML |
| 56 | +child.parentNode |
| 57 | +node.nextSibling |
| 58 | + |
0 commit comments