JS Enumerate all the icons in the CSS implementation code _javascript tips

Source: Internet
Author: User
Art to do the CSS style icon more and more, hand to write icon name is almost impossible to achieve. So there is this function point: the CSS style of all the icon class enumerated in a graphical format for the configuration of the selection of personnel!

Search a circle, found that the introduction of the article from the CSS to traverse things very little. So spent half a day to realize it! First look at the next selection icon Demo:


Here is the Easyui: a comboxtree.
This omits code that references CSS and JS libraries (jquery and Easyui libraries).
Html:

Copy Code code as follows:

<input id= "CC" class= "Easyui-combotree" style= "width:200px"; >

Javascript:
Copy Code code as follows:

function GetStyle () {
for (var i = 0; i < document.styleSheets.length; i++) {
VAR rules;
if (document.stylesheets[i].cssrules) {
Rules = Document.stylesheets[i].cssrules;
}
else {
Rules = Document.stylesheets[i].rules;
}
for (var j = 0; J < Rules.length; J + +) {
if (rules[j].selectortext.substr (0, 5) = = ". Icon")
$ (' #cc '). Combotree (' tree '). Tree (' append ', {
Data: [{
ID:RULES[J].SELECTORTEXT.SUBSTR (1),
TEXT:RULES[J].SELECTORTEXT.SUBSTR (1),
ICONCLS:RULES[J].SELECTORTEXT.SUBSTR (1)
}]
});
}
}
}
$ (function () {
GetStyle ();
});

There are several possible problems:
1. Large project styles can be huge, and this traversal is clearly not possible and needs to be assigned to stylesheets.
2. If the various size of the icon may be used easyui-combotree not very reasonable.
Finally through the configuration icon generated menu effect:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.