Logo

替换html的某个标签,使用jQuery将一个标签替换为另一个标签

photo

2022年04月29日

建立在Felix的答案上。

$(‘code’).replaceWith(function() {

var replacement = $(‘

').html($(this).html());

for (var i = 0; i < this.attributes.length; i++) {

replacement.attr(this.attributes[i].name, this.attributes[i].value);

}

return replacement;

});

这将code在替换pre标签中复制标签的属性。

编辑:这将取代甚至code是里面的标签innerHTML等的code标签。

function replace(thisWith, that) {

$(thisWith).replaceWith(function() {

var replacement = $(”).html($(this).html());

for (var i = 0; i < this.attributes.length; i++) {

replacement.attr(this.attributes[i].name, this.attributes[i].value);

}

return replacement;

});

if ($(thisWith).length>0) {

replace(thisWith, that);

}

}

replace(‘code’,’pre’);

橙子主题打折出售

其实我不卖,主要是这里是放广告的,所以就放了一个
毕竟主题都没做完,卖了也是坑.

购买它
所有附件
该文章没有附件.
本文为原创文章,请注意保留出处!

热门文章

EWS(Exchange Service)基本使用(获取个人会议,会议室会议内容,会议室列表,发送会议,修改会议,删除会议) 最近公司要求和exchange服务对接,所以稍微研究了一下官方文档,做出以下总结,欢迎大家补充。先...EWS(ExchangeService)基本使用(获取个人会议,会议室会议内容,会议室列表,发送会议,修改会议,删除会议) 作者:Pastore Antonio
1598 浏览量
Sql Server 部署SSIS包完成远程数据传输 本篇介绍如何使用SSIS和作业完成自动更新目标数据任务。**温馨提示:如需转载本文,请注明...SqlServer部署SSIS包完成远程数据传输 作者:Pastore Antonio
1592 浏览量
SQL Server AG集群启动不起来的临时自救大招 背景前晚一朋友遇到AG集群发生来回切换不稳定的情况,情急之下,朋友在命令行使用命令重启WSFC集群...SQLServerAG集群启动不起来的临时自救大招 作者:Pastore Antonio
1582 浏览量
SharePoint2010升级到SharePoint2013操作手册 SharePoint2010升级到SharePoint2013操作手册目录第一章...SharePoint2010升级到SharePoint2013操作手册 作者:Pastore Antonio
1570 浏览量
C# DataTable 某一列求和 列为数字类型doubletotal=Convert.ToDouble(datatable.Com...C#DataTable某一列求和 作者:Pastore Antonio
1565 浏览量