Created
June 4, 2014 09:22
-
-
Save aa65535/afb8e1882253eac805bd to your computer and use it in GitHub Desktop.
删除CSS中指定的选择器属性
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
</head> | |
<body> | |
<textarea id="css" style="margin: 2px; width: 400px; height: 429px;"></textarea> | |
<textarea id="rules" style="margin: 2px; width: 400px; height: 429px;"></textarea> | |
<button id="submit">submit</button> | |
<script> | |
document.getElementById('submit').onclick = function() { | |
'use strict'; | |
var css = '}' + document.getElementById('css').value; | |
var rules = document.getElementById('rules').value.split('\n'); | |
var len = rules.length; | |
var i, u; | |
for (i = 0; i < len; i++) { | |
if (rules[i]) { | |
u = new RegExp('\\}\\s*' + rules[i].replace(/(\*|\.|\+|\^|\[|\]|\(|\))/g, '\\$1') + '\\s*\\{([\\s\\S]*?)\\}', 'ig'); | |
css = css.replace(u, '}'); | |
console.log(u, css.length); | |
} | |
} | |
document.getElementById('css').value = css.trim().slice(1); | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment