Skip to content

Instantly share code, notes, and snippets.

@aa65535
Created June 4, 2014 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aa65535/afb8e1882253eac805bd to your computer and use it in GitHub Desktop.
Save aa65535/afb8e1882253eac805bd to your computer and use it in GitHub Desktop.
删除CSS中指定的选择器属性
<!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