function getClass(obj, attr) { var aArray = [];//定义一个新的空数组 var i = 0; var aAll = document.getElementsByTagName('*');//获取obj对象下面所有的节点 for (i = 0; i < aAll.length; i++) { if (aAll[i].className == attr) {//判断当前对象的class名称是不是符合传进来的参数 aArray.push(aAll[i]);//如果符合则push到到aArray数组里边 alert(aAll[i]); } } return aArray;//最后return一下 } function insertHtml(where, el, html) { where = where.toLowerCase(); if (el.insertAdjacentHTML) { switch (where) { case "beforebegin": el.insertAdjacentHTML('BeforeBegin', html); return el.previousSibling; case "afterbegin": el.insertAdjacentHTML('AfterBegin', html); return el.firstChild; case "beforeend": el.insertAdjacentHTML('BeforeEnd', html); return el.lastChild; case "afterend": el.insertAdjacentHTML('AfterEnd', html); return el.nextSibling; } throw 'Illegal insertion point -> "' + where + '"'; } var range = el.ownerDocument.createRange(); var frag; switch (where) { case "beforebegin": range.setStartBefore(el); frag = range.createContextualFragment(html); el.parentNode.insertBefore(frag, el); return el.previousSibling; case "afterbegin": if (el.firstChild) { range.setStartBefore(el.firstChild); frag = range.createContextualFragment(html); el.insertBefore(frag, el.firstChild); return el.firstChild; } else { el.innerHTML = html; return el.firstChild; } case "beforeend": if (el.lastChild) { range.setStartAfter(el.lastChild); frag = range.createContextualFragment(html); el.appendChild(frag); return el.lastChild; } else { el.innerHTML = html; return el.lastChild; } case "afterend": range.setStartAfter(el); frag = range.createContextualFragment(html); el.parentNode.insertBefore(frag, el.nextSibling); return el.nextSibling; } throw 'Illegal insertion point -> "' + where + '"'; } //调用1 getClass("div","banner")[0].innerHTML='我们来了'; //调用2 //insertHtml('afterBegin', document.getElementById("csContentEnd"), "<dd>在文本前容器内插入内容</dd>"); //insertHtml('beforeEnd', elem, "<dd>在文本后容器内插入内容</dd>"); insertHtml('beforeBegin', document.getElementById("csContentEnd"), "<dd>在文本前容器外插入内容</dd>"); //insertHtml('afterEnd', elem, "<dd>在文本后容器外插入内容</dd>");
下载说明
☉本站所有源码和资源均由站长亲自测试-绝对保证都可以架设,运营!
☉如源码和资源有损坏或所有链接均不能下载,请告知管理员,
☉本站软件和源码大部分为站长独资,资源购买和收集,放心下载!
☉唯一站长QQ:1004003180 [人格担保-本站注重诚信!]
☉购买建议E-mail:1004003180@qq.com 源码收购 E-mail:1004003180@qq.com
☉本站文件解压密码 【文章内都自带解压密码,每个密码不同!】