这里有三个常用操作DOM,但并不属于内置的函数:
增加类属性:
function addClass() { if (!element.className) { element.className = value; } else { newClassName = element.className; newClassName += " "; newClassName += value; element.className = newClassName; }}在目标节点后增加新节点:
function insertAfter(newElement, targetElement) { var parent = targetElement.parentNode; if (parent.lastChild == targetElement) { parent.appendChild(newElement); } else { parent.insertBefore(newElement, targetElement.nextSibling); }}增加绑定页面加载时执行的事件:
function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } }}新闻热点
疑难解答