简体   繁体   中英

Using special symbols in HTML and Javascript

I'm trying to figure out what is the proper way to use the "not" operator (Negation) which looks like: ¬ (UTF-8: U+00AC ) in JavaScript. I could use:

<span>¬A</span>

But I'm not sure if it is the proper way and if its been supported on all (or most) of the modern browsers and mobile. I tried to find a previous topic on this matter but could not find any. The wanted result is to display this operator beside A .

Correct escape sequences for HTML are: &#x00AC, followed by ';A', and for javascript - either '\\xACA' or '\¬A'.

"meta charset" is always advisable to include, but it does not affect the escapes.

I added ';' after the HTML escape sequence: for some reason it wasn't needed if instead of 'A' there is, for example, 'k', I didn't know. Semicolon has to be added.

That would be &#x00ac; The "x" is needed because that's a hex encoding.

So

<span>&#x00ac;A</span>

Make sure you include <meta charset="utf-8"> in your <head> .

If you are properly using UTF-8 (which is to say that your HTML, JS, and CSS files are all encoded in UTF-8, <meta charset="utf-8"> is present in the <head> , and HTTP headers all define the charset as UTF-8), there should be no need to encode the symbol at all. Simply write ¬ , exactly as you have done here.

The only symbols you need to encode are < and & (also ' and/or " in attributes). Most would also recommend encoding > and the non-breaking space, to avoid confusion. I encode all of these, but nothing else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM