如何使用Javascript检查字符串中是否有CSS属性? 检查1000多个句子的代码
如何使用Javascript检查字符串中是否有CSS属性? 检查1000多个句子的代码,javascript,jquery,Javascript,Jquery,Javascript是否有内置的CSS索引我可以对照检查句子 目前 如果我想检查以下句子的CSS属性,我必须创建一个数组,其中包含CSS属性。然后对照整个数组检查每个句子。 阵列 css_checker = [ "width","height","background","background color", "text decoration line", "right", "table layout", "page break before", //and on… and… on and
Javascript
是否有内置的CSS索引
我可以对照检查句子
目前
如果我想检查以下句子的CSS属性
,我必须创建一个数组
,其中包含CSS属性。
然后对照整个数组检查每个句子。
阵列
css_checker = [
"width","height","background","background color", "text decoration line", "right",
"table layout", "page break before", //and on… and… on and on………………
// I really don't want to use this array
// Using this is like a last resort
// I was hoping for a better way than this
]
输入
a = "A CSS property named animation fill mode is in this string"
b = "There are no CSS properties in this string"
c = "Width, height, and animation properties are in this string"
d = "Column rule width and transform origin are in this string"
if ( /*Sentence has CSS property*/ ) {
//run this code
}
匹配 答:此字符串中有一个名为
动画填充模式的CSS属性
b:这个字符串中没有CSS属性
c:宽度
,高度
,以及动画
属性都在这些字符串中
d:列规则宽度
和转换原点
在这些字符串中
输出
a = "A CSS property named animation fill mode is in this string"
b = "There are no CSS properties in this string"
c = "Width, height, and animation properties are in this string"
d = "Column rule width and transform origin are in this string"
if ( /*Sentence has CSS property*/ ) {
//run this code
}
a:是的
b:错
c:是的
d:是的
如何使用它
a = "A CSS property named animation fill mode is in this string"
b = "There are no CSS properties in this string"
c = "Width, height, and animation properties are in this string"
d = "Column rule width and transform origin are in this string"
if ( /*Sentence has CSS property*/ ) {
//run this code
}
我想做的是
找出第一个CSS属性的位置…然后在该点拆分它。
例子
输入
此字符串中有一个名为“动画填充模式和宽度”的CSS属性
匹配
名为动画填充模式和宽度的CSS属性在此字符串中
输出
动画填充模式和宽度在此字符串中您可以在此使用一些
来测试字符串。如果您是从元素文本抓取,只需传入element.textContent
函数包含scssprop(str){
css_checker=[“宽度”、“高度”、“背景”、“背景色”、“文本装饰线”、“右侧”、“表格布局”、“前分页符”、“动画”、“列规则宽度”、“变换原点”];
返回css_checker.some(prop=>str.toLowerCase().includes(prop));
}
log(containsCSSProp(“此字符串中有一个名为animation fill mode的CSS属性”);
log(containsCSSProp(“此字符串中没有CSS属性”);
log(containsCSprop(“宽度、高度和动画属性在此字符串中”);
log(containsCSSProp(“列规则宽度和转换原点在此字符串中”)代码>
让css_checker=['width'、'height'、'background'、'background color'、'text decoration line'、'right'、'table layout'、'page break before'];
设a='此字符串中有一个名为animation fill mode的CSS属性';
设b='此字符串中没有CSS属性';
设c='宽度、高度和动画属性在此字符串中';
设d='列规则宽度和转换原点在此字符串中';
for(设i=0,max=css\u checker.length;i 校验字符串(d,css\U校验符)代码>我更新了问题…你能检查一下我想做的是
部分吗?还有…性能方面…如果我检查10000个句子…这是一个好方法吗?