admin管理员组

文章数量:1418361

My question regarding the \'add \' backslash-single quote that being passed into the method validate, what is the use of that backslash-single code?

document.writeln('<td width="12%"><INPUT name=btnAdd type=button value="Add" align="right" onclick="if(Validate(this.form,\'add\',\'<%=i%>\',\'N\'))></td>');

My question regarding the \'add \' backslash-single quote that being passed into the method validate, what is the use of that backslash-single code?

document.writeln('<td width="12%"><INPUT name=btnAdd type=button value="Add" align="right" onclick="if(Validate(this.form,\'add\',\'<%=i%>\',\'N\'))></td>');
Share Improve this question edited Jan 4, 2014 at 13:03 Ashley Medway 7,3097 gold badges53 silver badges73 bronze badges asked Jan 4, 2014 at 12:39 user3160236user3160236 131 silver badge3 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

Wele to Stack Overflow.

Backslash tells the code that this isn't a part of qoutation, it instead is a text character. And it is known as escape character which is used to escape the code start and ending points. For example:

alert("Hi, " is a double qoute"); 

won't work, since the qoutation of the string has been ended! Might provide an exception if environment throws one. While this one:

alert("Hi, \" is a double qoute");

Won't show up any error. And you will get the written text as the alert popup. You can even see the difference in the Stack Overflow code viewer.

Your code:

this.form,\'add\',\'<%=i%>\',\'N\')

Will be executed as:

this.form, 'add', '<%=i%>, 'N' 

And you will get the value as needed!

It is called escape character. It escapes the special meaning of the next character.

Here it depresses the power of the quote. Usually used to nest the quotes in JavaScript

If you are confusing with that one,then change it as

document.writeln("<td width='12%'><INPUT name=btnAdd type=button value='Add' align='right' onclick='if(Validate(this.form,\'add\',\'<%=i%>\',\'N\'))></td>");

The backslash () is an escape character in Javascript (along with a lot of other C-like languages). This means that when Javascript encounters a backslash, it tries to escape the following character. For instance, \n is a newline character (rather than a backslash followed by the letter n).

And This kind of string '/\S+@\S+.\S+/' is called Reg-ex. Regular expressions are used to perform powerful pattern-matching and "search-and-replace" functions on text.basically it is used for validation.

本文标签: javascriptBackslashsingle quote 39Stack Overflow