Javascript JQuery替换标签

我有一个令人满意的区域,当用户完成编辑后,我会将数据保存到文件中。 当用户使用第一个浏览器然后另一个浏览器时,由contenteditables创建的不同样式会导致代码混乱和不兼容。

我想知道是否有办法用“标准”标签(例如xxx替换Chrome中创建的XXX标签。

提前致谢

你可以试试这个:

 $('span').each(function(){ // iterate to the all the spans if($(this).css('font-weight') == 'bold'){ // check if font is bold $(this).contents().unwrap().wrap('');​ } // unwrap the content and wrap it }); 

那么,这里发生的是:

  1. 迭代文档中的所有跨度
  2. 检查css样式是否为“粗体”
  3. 如果为true,则首先打开它所包含的内容并用您选择的标签包装它

所以类似地你必须分别检查所有其他css样式并相应地替换/包装它。

使用:

 $('span').each(function(){ // iterate to the all the spans if($(this).css("font-weight") == "bold"){ // $(this).contents().unwrap().wrap('');​ } }); 

工作演示