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
4 Answers
Reset to default 3Wele 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
版权声明:本文标题:javascript - Backslash-single quote ' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745287832a2651604.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论