版权声明:本文为大都督作者的原创文章,未经 大都督 允许也可以转载,但请注明出处,谢谢! 共勉! https://blog.csdn.net/qq_37335220/article/details/85109058
1. 效果图
2. html代码
<!DOCTYPE html>
<html>
<head>
<title>jQuery-使用replaceWith()和replaceAll()方法替换元素节点</title>
<style type="text/css">
body{font-size: 13px}
span{font-weight: bold;}
p{background-color: #eee;padding: 5px;width: 200px;}
</style>
</head>
<body>
<p>姓名:<span id = "Span1"></span></p>
<p>邮箱:<span id = "Span2"></span></p>
<script src="../jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var html = '<span title="replaceWith">大都督</span>';
$("#Span1").replaceWith(html);
var html2 = '<span title="replaceAll">[email protected]</span>';
$(html2).replaceAll("#Span2");
});
</script>
</body>
</html>