如何改写JavaScript工具函数insertAfter和addLoadEvent为长尾?

2026-04-06 19:021阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计144个文字,预计阅读时间需要1分钟。

如何改写JavaScript工具函数insertAfter和addLoadEvent为长尾?

javascript@param newElement 添加的新元素@param targetElement 已有目标元素在已有元素后添加一个新元素*/function insertAfter(newElement, targetElement) { var parent=targetElement.parentNode; if (parent.lastChild===targetElement) { parent.appendChild(newElement); } else { parent.insertBefore(newElement, targetElement.nextSibling); }}

如何改写JavaScript工具函数insertAfter和addLoadEvent为长尾?

gistfile1.txt

/* *@param newElement 加入的新元素 *@param targetElement 已有目标元素 *在已有元素后加入一个新元素 */ function insertAfter(newElement, targetElement) { var parent = targetElement.parentNode; if (parent.lastChild == targetElement) { parent.appendChild(newElement); } else { parent.insertBefore(newElement, targetElement.nextSibling); } } /* *@param func 绑定到onload事件的函数的名字 *功能:将需要绑定到onload事件的函数载入队列 */ function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } }

本文共计144个文字,预计阅读时间需要1分钟。

如何改写JavaScript工具函数insertAfter和addLoadEvent为长尾?

javascript@param newElement 添加的新元素@param targetElement 已有目标元素在已有元素后添加一个新元素*/function insertAfter(newElement, targetElement) { var parent=targetElement.parentNode; if (parent.lastChild===targetElement) { parent.appendChild(newElement); } else { parent.insertBefore(newElement, targetElement.nextSibling); }}

如何改写JavaScript工具函数insertAfter和addLoadEvent为长尾?

gistfile1.txt

/* *@param newElement 加入的新元素 *@param targetElement 已有目标元素 *在已有元素后加入一个新元素 */ function insertAfter(newElement, targetElement) { var parent = targetElement.parentNode; if (parent.lastChild == targetElement) { parent.appendChild(newElement); } else { parent.insertBefore(newElement, targetElement.nextSibling); } } /* *@param func 绑定到onload事件的函数的名字 *功能:将需要绑定到onload事件的函数载入队列 */ function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } }