Understanding of the use and escape of single quotation marks (& amp; #39;) and double quotation marks () in js

Source: Internet
Author: User
Tags add time

I have been drawing pages over the past few days. As a developer, I want to draw pages because everything on the pages of the current project is obtained from the database, that is, dynamic, similar to designing our own personal QQ space, but because it is a large platform and has a custom business concept, all of them are more complicated and we will not talk about it here, what I call "Drawing pages" is how to combine data logic into HTML. The biggest problem I have encountered is what I want to talk about today;

There is a query on a page. Of course, the query conditions and field types are dynamic. Different text boxes should be generated based on the data type. If varchar2 is used, different fields will be generated, if date is used to generate the add time and select js, there is a button to add a new condition group on the page to link to a js event, which requires judgment on the text box, the judgment part is as follows;

If (tlist [index]. value = "date ")
{
Table. rows [t]. cells [2]. innerHTML = <input name = "+ mlist [index]. value + biduinum + "type =" text "size =" 12 "style =" width: 200px "readonly =" readonly "onclick =" WdatePicker ({dateFmt: "yyyy-MM-dd"}) "onfocus =" WdatePicker ({dateFmt: "yyyy-MM-dd"}) "class =" Wdate "/>;
}
Else
{
Table. rows [t]. cells [2]. innerHTML = <input name = "+ mlist [index]. value + biduinum + "type =" text "size =" 12 "style =" width: 200px "/>;
}

The focus is on the red part. I thought it was understandable to write this Code. However, if this code is executed once, the js error will be reported. The error message is "syntax error". js itself is a weak language, single quotation marks and double quotation marks can be confused if they are used, but they must be differentiated if they are used together. For example, in the previous code, I can replace single quotation marks and double quotation marks, however, if you only change one of them, you need to use the + link, and the meaning is also different, for example

"B" is acceptable, but "B" is prone to errors. "+" B "+" "is required ""

The problem cannot be solved through the change of single quotes and double quotes. I began to look for other ideas. I tried to use the escape character to solve the problem, as shown below:

Onclick = "WdatePicker ({dateFmt:" yyyy-MM-dd "})"

But it still does not work. I personally think the reason is that js is still in the role of html, rather than java, so I thought of using & quot; to solve it,

Table. rows [t]. cells [2]. innerHTML = <input name = "+ mlist [index]. value + biduinum + "type =" text "size =" 12 "style =" width: 200px "readonly =" readonly "onclick =" WdatePicker ({dateFmt: & quot; yyyy-MM-dd & quot;}) "onfocus =" WdatePicker ({dateFmt: & quot; yyyy-MM-dd & quot ;}) "class =" Wdate "/>;

 

The problem is solved. For the first time in my life, I felt the magic of this thing. I used it only. & nbsp;. It seems that in the world of programs, everything has its own meaning, even when we have to eliminate them, we need to know their meaningful part, because these meaningful things may be of great help to us at some point in time, in addition, replacement of their products may not be able to pass on all their advantages.

Green Channel: Please follow my favorites to contact me

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.