无法“替换”样式“中的内容 - 其中”html“存储在变量中

Not able to `replace` content in `style` - where the `html` is stored in variable

本文关键字:html 其中 存储 变量 样式 替换 无法 中的内容      更新时间:2023-09-26

我正在尝试通过replacing一个字符串来更新style html,但不起作用。 我无法获得最终更新的html

这是我的尝试:

var html = "<style>043BF83A8FB24A418DA4248840101D .cls_0 {font:26px 'Arial';}</style><div>testing</div>"
html += $(html).html(function(_,h){
  $(h).find('style').html().replace(/^'w+ ('.'w+)/gm,'$1');
});
console.log(html); //throws the error.

斯菲德尔

它对我有用..

var html = "<style>043BF83A8FB24A418DA4248840101D .cls_0 {font:26px 'Arial';}</style><div>testing</div>";
var $h = $('<div>'+html+'</div>');
$h.find('style').html(function(_,h){ return h.replace(/^'w+ ('.'w+)/gm,'$1'); });
var updated = $h.html();
console.log(updated);

谢谢大家!