将 html 内容替换为找到的内容

Replacing a html content with found content

本文关键字:替换 html      更新时间:2023-09-26

我正在尝试替换HTML正文中的已建立内容,如下面的代码所示。

var fontReplacer = $("body").html().replace(/'{fontsize:(.*?)'}(.*?(({fontsize'})|$)/g,'<span style="font-size:$1px">$2</span>');
  $("body").html(fontReplacer);

但是在执行此代码后,剩余函数不起作用。是否编写代码在此处用 12px 文本替换像 {fontsize:12}12px text here{font} 这样的内容(大小为 12px)请帮助我做错的地方

你在HTML中搜索的是什么基础的东西,哪个部分。

var sel = $('body').find('div'); //mention what which element you are searching for
var sel = $('body').find('span');
for(i = 0; i< sel.length; i++)
 $(sel).css('font-size','1px');

同样适用于跨度