Cool
Cool
Published on 2021-05-31 / 22 Visits
0
0

jquery 替换原来的html内容

  1. replaceWith() 使用括号内的内容替换所选择的内容。
$("#div").replaceWith("<div id="div2">div2</div>");

使用方法如上,将ID为div的元素替换为ID为div2的DIV元素。


  1. replaceAll() 将选择的内容替换到括号内的选择器。
$("<div>替换后的内容</div>").replaceAll("p");

使用方法如上,将所有的p标签替换为选择的DIV标签。


Comment