Js根据class名替换html标签内容 ,在某标签前后添加内容
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>");
Js根据class名替换html标签内容 ,在某标签前后添加内容的更多相关文章
- notepad++每行首尾添加内容
有时候我们需要给一个文本文件的每行前面或后面添加一些内容,例如我们一个文本文件里存放了很多图片的地址,现在我们需要把这些图片批量转换成html标记 百度经验:jingyan.baidu.com 工具/ ...
- 通过js去掉所有的html标签,得到HTML标签中的所有内容
<script> //替换掉所有的 html标签,得到Html标签中的内容 var s="<P><FONT face=宋体 color=#000000> ...
- js清除节点内容(改变标签元素)
<!DOCTYPE HTML><html> <head> <meta http-equiv="Content-Type" c ...
- 通过js给某个标签添加内容或者删除标签
添加内容 //先保存div中原来的html var tag = document.getElementById("tag").innerHTML; //构造新的内容 var cou ...
- 如何用PC标签在列表页中调出文章内容 phpcms
如何用PC标签在列表页中调出文章内容 phpcms v9 moreinfo=”"参数说明 {pc:content action="lists" catid="$ ...
- textarea与标签组合,点击标签填入标签内容,再次点击删除内容(vue)
需求:将textarea与span标签组合,点击标签自动填入标签文本内容,再次点击删除标签文本对应内容 原理:点击标签时,将标签内容作为参数,将内容拼接在textarea的value后面,再次点击标签 ...
- 内容模块PC标签调用说明
内容模块 模块名:content 模块提供的可用操作 操作名 说明 lists 内容数据列表 relation 内容相关文章 hits 内容数据点击排行榜 category 内容栏目列表 positi ...
- 原创:js代码, 让dedecms支持Tag选择, 添加内容更为方便,不用手输Tag
dedecms在编辑修改内容时,TAG标签需要手动输,中文的Tag, 中间还得用半角字符','分隔, 输入法切来切去很不方便, 于是动手改后台代码, 利用后台的tags_main.php, 让d ...
- phpcms V9首页、列表页以及内容页调用标签
1.页面标题:{$title} 2.发表时间:{$inputtime} 3.内容来源:{$copyfrom} 4.文章内容:{$content} 5.缩略图地址:{$thumb} 6.组图列表: {l ...
随机推荐
- 第九十四节,html5+css3移动手机端流体布局,旅游部分,媒体查询
html5+css3移动手机端流体布局,旅游部分,媒体查询 媒体查询 媒体查询是手机网站和自适应网站的重要部分,媒体查询可以根据不同的屏幕大小,做响应的处理,如文字的大小,区块隐藏等等 媒体查询,这里 ...
- POJ 1922 Ride to School#贪心
(- ̄▽ ̄)-* //C跟着a君骑,然后更快的b君来了,C又跟着b君骑, //接着最快的d君来了,C就去跟着d君了, //最后最快的d君到达目的地时,C也就到了 //所以C的到达时间,就是最早到达的那 ...
- shell脚本学习(三)
1.在grep中, ^标记着单词的开始, $ 标记着单词的结束. 查看一个单词是否在linux自带的词典中,脚本如下: #bin/sh #文件名:checkword.sh word=$1 grep & ...
- ubuntu下安装UltraEdit
在windows下常年使用UltraEdit来查看log,现在突然切换到ubuntu下,系统自带的Text Editor相当不适应:只有自己安装了. 首先,需要下载安装包,可以去:http://www ...
- linux nfs开启
nfs设置: NFS的配置过程很简单.在服务器端中编辑/etc/exports文件,添加如下内容: /home/cotton/data/cotton/zghy 192.168.2.*(rw,s ...
- docker network
前言:前面的部分一直都是单机跑docker,但实际生产环境不可能只用一台来跑.肯定会用到多台,因为他们都是内部私有ip,那么多台主机之间的容器如何通信?这个是个很头疼的问题!目前主流几种方法如下: 1 ...
- Find and run the whalesay image
Find and run the whalesay image People all over the world create Docker images. You can find these i ...
- tree btn
@* <a href="javascript:void(0)" onclick="saveChecked()" ><img sr ...
- 使用cocoapods的两个大坑的修改方法
1.报错内容: [!] The dependency `ReactiveCocoa (= 2.1.8)` is not used in any concrete target. The depende ...
- fragement切换动画效果的实现
标准动画: fragementTransaction.setTransition(FragmentTransation.TRANSIT_FRAGMENT_CLOSE); 自定义动画: fragemen ...