AI智能
改变未来

js写封装函数insertAfter()

<!DOCTYPE html><html leng = \'en\'><head><meta charset = \'UTF-8\'/><style></style></head><body><div><i></i><b></b><span></span></div><p></p><!--<div><a></a><em></em></div>--><script>var i = document.getElementsByTagName(\'i\')[0];var b = document.getElementsByTagName(\'b\')[0];var p = document.getElementsByTagName(\'p\')[0];var span = document.getElementsByTagName(\'span\')[0];var div = document.getElementsByTagName(\'div\')[0];Element.prototype.insertAfter = function(a, b){if(a.nextElementSibling === null){a = a.nextSibling;}else{a = a.nextElementSibling;}this.insertBefore(b, a);}div.insertAfter(span, p);/*var em = document.getElementsByTagName(\'em\')[0];var a = document.getElementsByTagName(\'a\')[0];Element.prototype.insertAfter = function(a, b){//a = a.nextElementSibling;this.insertBefore(b, a);}var div = document.getElementsByTagName(\'div\')[0];div.insertAfter(a, em);*/</script></body></html>
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » js写封装函数insertAfter()