Home >Web Front-end >JS Tutorial >A brief analysis of single quotation marks and double quotation marks in Js_javascript skills

A brief analysis of single quotation marks and double quotation marks in Js_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:17:061163browse

There is actually no difference between single quotes and double quotes, it depends on how you get used to it

-------------------Incorrect
-------------------Correct

Use double quotes within double quotes like this:
var str = "abc"def"ghi"
Use a backslash to disable parsing of double quotes.

The following is an excerpt from me, I hope it is useful to you:

When writing the onclick event processing code for a button on a web page, I accidentally wrote it as follows:

After IE prompts an error, then casually change it to:

The result is still wrong.
At this time, I couldn't figure it out, although I knew the most direct solution was to write it like this:

But why do the escape characters in JavaScript have no effect?

Later I found a normal piece of code:

Only then did I understand that this , it still falls under the jurisdiction of HTML, so the escape characters should be HTML instead of javascript. The method of using two double quotes is vbScript, "This method is used by javascript, and HTML uses ". In addition, you can also use: ", '.

Various expression methods are listed below:

Copy code The code is as follows:









< input value="Two single quotes - error" type="button" onclick="alert(''OK'');" />















< ;input value="HTML escape character"(& # x 2 2 ;)-OK" type="button" onclick="alert('OK');" />

< ;input value="HTML escape character '(& # x 2 7 ;)-OK" type="button" onclick="alert('OK');" />

< ;input value="HTML escape character"(& q u o t ;)-OK" type="button" onclick="alert("OK");" />









Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn