JavaScript ASP Tutorial Lesson Four simultaneous use of VBScript and Javascript_asp basics

Source: Internet
Author: User
Begin:
You can have JavaScript and VBScript implement music from the same table. Look at the following script:
<textarea id="runcode70728"><% @LANGUAGE = "javascript"%> <script language= "javascript" runat= "Server" > Function jsgreeting () { Return "Greetings from a JavaScript Function"; } </SCRIPT> <script language= "VBScript" runat= "Server" > Function vbgreeting () vbgreeting= "Greetings F" Rom a VBScript function "End Function function Todollars (x) todollars=formatcurrency (x) End Function </script > <% var a = 2; var B = 2; var c = Add (a,b) c + = "(two numbers are added by JavaScript," C + = "and then into formatted by VBScript.)" function Add (x,y) {result = x + y; result = Todollars (result); return result; } Response.Write ("<ptml>\r") Response.Write (jsgreeting () + "\ R") Response.Write (vbgreeting () + "\ r") Response . Write (c + "\ r") Response.Write ("</ptml>\r")%></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

RUNAT:
Let's break it down from beginning to end. The following list is a simple and independent javascript:

If it weren't for the humble runat= "Server," it would look like a simple javascript you might see on the client.
The Runat property tells the server to execute it on the server side, so the client will never see it. You can also set the property to runat= "client" so that you can skip the server side and execute it directly on the client.
By the way, it cannot be placed inside the ASP tag.
Look at the following VBScript:
Function vbgreeting ()
Vbgreeting= "Greetings from a VBScript Function"
End Function
This VBScript implements the same functionality as JavaScript. There's nothing special about it.
However, the following VBScript has something special.
Function Todollars (x)
Todollars=formatcurrency (x)
End Function
Reference:
The function above returns a parameter from JavaScript. Then he would return the most appropriate value to JavaScript. Let's take a look at how function todollars (x) is referenced.
function Add (x,y)
{
result = x + y;
result = Todollars (result);
return result;
}
function Add (x,y) is a JavaScript function. From the middle of the function you can see
result = Todollars (result);
The line above is actually a call from VBScript to JavaScript.
Warning:
As a warning. When you create a script with the Runat attribute, you are actually arranging the order in which it is executed. I'm not going to go into that, because the order of execution depends on the situation.
Here's what I'll go into: Use the Runat property only on functions (and the global variables that are called within the function). Don't put the top layer of code in it because you can't guarantee that the top-level code will change the order of execution with this technique.

Original and example address of this section: http://aspjavascript.com/lesson04.asp
Original Author: James Clark translation: Huahua reprint Please specify
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.