Javascript call method with parameters in the background

Source: Internet
Author: User

1. Background method:

Protected string csharpvoid (string strcc)

{

Strcc = "http: //" + strcc; return strcc;

}

2. JavaScript method on the front-end page: <script language = "JavaScript" type = "text/JavaScript"> var v = "www.baidu.com "; vaR S = '<% = csharpvoid ("' + V + '") %>'; document. write (s); </SCRIPT> try it. I'm in Visual Studio. net2005 test successful!

The result is a http://www.baidu.com string written on the page!

Take a closer look at this sentence: var S = '<% = csharpvoid ("' + V + '") %>'; double quotation marks and single quotation marks in it!

The reason for this problem lies in the nonstandard code writing: Your var S = "<% = csharpvoid (" www.esoutong.com ") %> "; there is no problem with double quotes in this sentence and it can be explained successfully. However, to keep the code clean and easy to read, you still need to develop a good coding habit to make the code easier to understand, avoid unnecessary errors caused by nonstandard coding habits!

Written in Javascript tutorials and other books: You can use single quotes or double quotes in Javascript. However, you can use single quotes or double quotes when quotation marks are required, make the code clear and easy to read and avoid unnecessary errors. When csharpvoid ("") must use double quotation marks, you must use single quotation marks when defining var S, if you want to replace www.baidu.com with a variable with double quotation marks, an error is returned (var s = '<% = csharpvoid ("' + V + '") %> '; vaR S = "<% = csharpvoid (" "+ V +" ") %>"; cannot be interpreted successfully ), this error is caused by nonstandard code writing. Therefore, standard code writing can avoid such errors!

Note: The following is an error message about the netizen Gao _ Chao: var S = "<% = csharpvoid ('www .baidu.com ') %>, in Visual Studio. net2005 won't be compiled successfully. The [csharpvoid] After [<% =] is the background method, which must use double quotation marks instead of single quotation marks to define the input string.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/yytt123622/archive/2008/10/31/3194275.aspx

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.