Har*_*rry 7 javascript css validation
我允许用户输入 css。
在客户端验证 CSS 的轻量且高性能的方法是什么?
我正在寻找 JavaScript 解决方案。我不想将 css 发送到某些远程服务器或其他任何东西。
上下文: 允许用户 CSS
谢谢。
编辑:NVM 关于这个问题。我开始使用服务器端验证器: https: //github.com/chriso/node-validator
Ash*_*raf -3
function getDefinedCss(s){
if(!document.styleSheets) return '';
if(typeof s== 'string') s= RegExp('\\b'+s+'\\b','i'); // IE capitalizes html selectors
var A, S, DS= document.styleSheets, n= DS.length, SA= [];
while(n){
S= DS[--n];
A= (S.rules)? S.rules: S.cssRules;
for(var i= 0, L= A.length; i<L; i++){
tem= A[i].selectorText? [A[i].selectorText, A[i].style.cssText]: [A[i]+''];
if(s.test(tem[0])) SA[SA.length]= tem;
}
}
return SA.join('\n\n');
}
// Then you check the class if exists by calling getDefinedCss('myclassname')
Run Code Online (Sandbox Code Playgroud)