Determine the optimal method of the input string as color type

zhaozj2021-02-16  45

In general, if we judge whether a given string is color type

Need to consider whether it is a 16-en-code code (such as #ffffff) or internal definition strings (such as ButtonFace, RED, Blue, etc.) or RGB () form

If we deliver its format in turn, we comply with the standard that will be quite spending time and code work.

I found a very simple and effective way in the app.

It is to create a character string that will be judged by document.createElement ().

Such as var ospan = document.createElement (" ");

Then judge whether ospan.style.color is empty, the string strcolor is an illegal color value otherwise legal

The following is example