jQuery节点的替换方法
上一节
下一节
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>13.6节点的替换方法</title>
<script src="../js/jquery-3.1.1.min.js"></script>
<script>
$(function(){
//替换方法1:replaceWith()
/*
$('#btn1').click(function(){
$('p').replaceWith('<div><b>apple</b></div>');
});
*/
//替换方法2:repalceAll()
$('#btn1').click(function(){
$('<div><b>apple</b></div>').replaceAll('p');
});
});
</script>
</head>
<body>
<input type="button" id="btn1" value="替换成英文">
<p>苹果</p>
</body>
</html>
运行效果

单击“替换成英文”按钮后


