我允許用戶輸入的CSS。javascript validate css
在客戶端驗證該css的輕量級和高性能方法是什麼?
我正在尋找一個javascript解決方案。我不想將css發送到某個遠程服務器或任何東西。
感謝。
編輯:在這個問題上的NVM。我開始使用服務器端驗證: https://github.com/chriso/node-validator
我允許用戶輸入的CSS。javascript validate css
在客戶端驗證該css的輕量級和高性能方法是什麼?
我正在尋找一個javascript解決方案。我不想將css發送到某個遠程服務器或任何東西。
感謝。
編輯:在這個問題上的NVM。我開始使用服務器端驗證: https://github.com/chriso/node-validator
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')
可以使用CSSLint引擎在應用程序中。其來源可在https://github.com/stubbornella/csslint
我去了js鏈接網站並輸入:
這是什麼? –
我也很好奇:)。 – cxw
我真的不知道:)這似乎是一個JS函數來檢查一個CSS類是否存在。不知道現在是否有效,但是因爲它在2012年標記爲正確答案,所以它應該在那個時間工作:D – Ashraf