Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用找到的内容替换html内容_Javascript_Jquery_Html_Css_Regex - Fatal编程技术网

Javascript 用找到的内容替换html内容

Javascript 用找到的内容替换html内容,javascript,jquery,html,css,regex,Javascript,Jquery,Html,Css,Regex,我正在尝试替换HTML正文中已建立的内容,如下面的代码所示 var fontReplacer = $("body").html().replace(/\{fontsize:(.*?)\}(.*?(({fontsize\})|$)/g,'<span style="font-size:$1px">$2</span>'); $("body").html(fontReplacer); var fontplacer=$(“body”).html().replace(/\{fo

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

var fontReplacer = $("body").html().replace(/\{fontsize:(.*?)\}(.*?(({fontsize\})|$)/g,'<span style="font-size:$1px">$2</span>');
  $("body").html(fontReplacer);
var fontplacer=$(“body”).html().replace(/\{fontsize:(.*)\}(.*)(({fontsize\})|$)/g,$2');
$(“body”).html(fontReplacer);
但在执行此代码后,reside函数不起作用。是否编写代码来将
{fontsize:12}12px text here{font}
之类的内容替换为12px text here(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');
var sel=$('body').find('div');//提及您正在搜索的元素
var sel=$('body')。find('span');
对于(i=0;i

类似地,对于span

下面的所有函数都不起作用。
意味着什么?看起来您的周围缺少引号regex@NickWilde-在它周围加引号会使它成为一个字符串。它不是字符串,而是一个正则表达式。看看在ConsoleNoPraveen中抛出的错误,我想动态添加大小,因为我得到了{fontsize:20}文本{fontsize}