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. In this way, I thought it was understandable.CodeOnce executed, JS errors are 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 but used, however, if we use them together, we need to differentiate them. For example, we can replace single quotes and double quotes in the previous Code. However, if we only change one of them, we need to use the plus sign link, which has different meanings, for example
"'B'" Yes, but "" B "" will cause an error. "+" 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. It seems that in the Program world, everything has its own meaning. Even when we have to eliminate them, we need to know what they mean, because these meaningful things may be of great help to us at some point in time, and replacing their products may not be able to inherit all their advantages.