javascript - Backslash-single quote ' - Stack Overflow

My question regarding the 'add ' backslash-single quote that being passed into the method v

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745287832a4620668.html

相关推荐

  • javascript - Backslash-single quote &#39; - Stack Overflow

    My question regarding the 'add ' backslash-single quote that being passed into the method v

    6小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信