Summary:
In HTML, some characters are reserved. The less than sign (<) and greater than sign (>) cannot be used in HTML because the browser mistakenly considers them to be labels. If you want to display reserved characters correctly, we must use the character entity in the HTML source code. To show the less than sign, we have to write this:< or & #60;
The characters commonly used character entity in HTML is a nonbreaking space ( ). The browser will always truncate the space in the HTML page. If you write 10 spaces in the text, the browser removes 9 of them before the page is displayed. To increase the number of spaces in the page, you need to use The character entity.
List of entities:
The following is a list of common entity tables
Show Results |
Description |
Entity name |
Entity number |
|
Space |
|
& #160; |
< |
Less than sign |
< |
& #60; |
> |
Greater than sign |
> |
& #62; |
& |
and number |
& |
& #38; |
" |
Quotes |
" |
& #34; |
¢ |
Score of |
¢ |
& #162; |
£ |
Pounds |
£ |
& #163; |
¥ |
Yen |
¥ |
& #165; |
€ |
Euro |
€ |
& #8364; |
§ |
Section |
§ |
& #167; |
© |
Copyright |
© |
& #169; |
® |
Registered trademarks |
® |
& #174; |
™ |
Trademark |
™ |
& #8482; |
X |
Multiplication sign |
× |
& #215; |
÷ |
Division Sign |
÷ |
& #247; |
Entity conversions:
Sometimes we need to work with the DOM in JS, but the entity converts the corresponding characters only when the browser renders the page. So we're going to have to write an entity conversion function ourselves. As follows:
functionunescapeentity (str) {var reg =/& (?: nbsp| #160 |lt| #60 |gt|62|amp| #38 |quot| #34 |cent| #162 |pound| #163 |yen| #165 |euro| #8364 |sect| #167 |copy| #169 |reg| #174 |trade| #8482 |times| #215 |divide| #247);/g,Entity= { ' ' : ‘ ‘, ' & #160; ' : ‘ ‘, ' < ' : ' < ', ' & #60; ' : ' < ', ' > ' : ' > ', ' &62; ' : ' > ', ' & ' : ' & ', ' & #38; ' : ' & ', ' " ' : ‘"‘, ' & #34; ' : ‘"‘, ' ¢ ' : ' ¢ ', ' & #162; ' : ' ¢ ', ' £ ' : ' £ ', ' & #163; ' : ' £ ', ' ¥ ' : ' ¥ ', ' & #165; ' : ' ¥ ', ' € ' : ' € ', ' & #8364; ' : ' € ', ' § ' : ' § ', ' & #167; ' : ' § ', ' © ' : ' © ', ' & #169; ' : ' © ', ' ® ' : ' ® ', ' & #174; ' : ' ® ', ' ™ ' : ' ™ ', ' & #8482; ' : ' ™ ', ' × ' : ' X ', ' & #215; ' : ' X ', ' ÷ ': ' ÷ ', ' & #247; ' : ' ÷ ' }; if(str = = =NULL) { return‘‘; } STR=str.tostring (); returnStr.indexof (';') < 0? Str:str.replace (Reg,function(chars) {returnEntity[chars]; }); }
Summary:
The advantage of using entity names instead of numbers is that names are easy to remember. The downside is that the browser may not support all entity names (the support for entity numbers is good).
HTML Entity Conversions