从`class`名称删除/替换不需要的前缀信息 [英] remove / replace unwanted prefixed info from `class` name
本文介绍了从`class`名称删除/替换不需要的前缀信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从后端获得 style
。它有它不需要的前缀。我会替换相同没有前缀。正确的方法是什么?
I am getting style
from backend. it has unwanted prefix with it. i would replace the same without the prefix. what would be the correct way?
这是我得到什么:
<style>
043BF83A8FB24A418DA4248840101DE5 .cls_0 {
font:26px 'Arial';
color:rgb(0,0,0);
font-weight:bold;
}
043BF83A8FB24A418DA4248840101DE5 .cls_1 {
font:26px 'Arial';
color:rgb(0,0,0);
}
043BF83A8FB24A418DA4248840101DE5 .cls_11 {
font:13px 'Arial';
color:rgb(0,0,0);
}
043BF83A8FB24A418DA4248840101DE5 .cls_12 {
font:16px 'Arial';
color:rgb(0,0,0);
font-weight:bold;
}
043BF83A8FB24A418DA4248840101DE5 .cls_13 {
font:16px 'Arial';
color:rgb(0,0,0);
}
</style>
这里是我需要的。
<style>
.cls_0 {
font:26px 'Arial';
color:rgb(0,0,0);
font-weight:bold;
}
.cls_1 {
font:26px 'Arial';
color:rgb(0,0,0);
}
.cls_11 {
font:13px 'Arial';
color:rgb(0,0,0);
}
.cls_12 {
font:16px 'Arial';
color:rgb(0,0,0);
font-weight:bold;
}
.cls_13 {
font:16px 'Arial';
color:rgb(0,0,0);
}
</style>
我尝试,但失败:
var styleText = $('style').get(1).html();
console.log(styleText); //throw error as "Uncaught TypeError: undefined is not a function"
推荐答案
这里有一个解决方案:
$('style').html(function(_,h){
return h.replace(/^\w+ (\.\w+)/gm,'$1');
});
这会删除任何字符串在一行的开始和任何< style>
元素。
This removes any string at the start of a line and before a class selector in any <style>
element.
这篇关于从`class`名称删除/替换不需要的前缀信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文