Home > Web Front-end > JS Tutorial > The difference and processing of single quotes and double quotes in javascript_Basic knowledge

The difference and processing of single quotes and double quotes in javascript_Basic knowledge

WBOY
Release: 2016-05-16 16:48:24
Original
1490 people have browsed it

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

Copy the code The code is as follows:

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

Enter double quotes Use double quotes like this:
var str = "abc"def"ghi"
Use backslashes to disable parsing of double quotes.

The following is what I excerpted, 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:
Copy code The code is as follows:



After IE prompts an error, then casually change it to:
Copy code The code is as follows:



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:
Copy code The code is as follows:



But why javascript The escape characters in have no effect?

Later I found a normal code:
Copy the code The code is as follows:



Only then did I understand that it turns out that at this time, it still belongs to HTML jurisdiction, so the escape characters should be HTML's, not JavaScript's. 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'');" />





























Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template