学吧就 - 博客园
2010-09-14 20:08
99 查看
想知道更多兼容的好东西 访问我的网站吧 boahy.com 呵呵 打个广告 www.boahy.com
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 + '"';
}
慢慢研究
insertAdjacentHTML
这个东西我还没研究明白 真是不好整啊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 + '"';
}
慢慢研究
相关文章推荐
- 此博客迁至博客园 http://www.cnblogs.com/windydays/
- 搬家去博客园了
- [原创]SQL Server 2005 镜像构建手册 - killkill - 博客园
- 从CSDN(博客园)搬家到wordpress
- 为什么不自己做网站,选择博客园?为什么程序不加密?为什么在淘宝销售软件?
- (转自博客园)Java文件操作---文件读取和写入示例
- 入驻博客园
- 搬家来博客园了
- QQ登陆功能的实现2 - rolends1986 - 博客园
- 在ASP.NET中支持断点续传下载大文件 - star163 - 博客园
- JSON.stringify 语法讲解 - 随风浪迹天涯 - 博客园
- redis源码笔记 - initServer - 刘浩de技术博客 - 博客园
- OAuth简介(摘自博客园)
- redis源码笔记 - 刘浩de技术博客 - 博客园
- [c/c++] linux c生成静态库&共享库 - bluefrog - 博客园
- 第一次在博客园上开通博客,大家多多关照
- 重开博客园博客
- 博客园,我又回来了
- [转]Vi/Vim查找替换使用方法 - HelloSUN - 博客园