Asp JavaScript 教程 - Lesson 04 Using VBScript with JavaScriptor

转载 2006年06月24日 13:50:00
 

Using VBScript with JavaScript

Get Started:

You can get JavaScript and VBScript to sing from the same sheet of music. Consider the script below.

<%@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 from 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 formatted into currency by VBScript.)"

function add(x,y)
	{
	result = x + y;
	result = toDollars(result);
	return result;	
	}

Response.Write("<HTML>/r")
Response.Write(JSGreeting() + "<BR>/r")
Response.Write(VBGreeting() + "<BR>/r")
Response.Write(c + " <BR>/r")
Response.Write("</HTML>/r")
%>

Click Here to run the script in a new window.

RUNAT:

Let me pick this apart from top to bottom. Directly below is a simple stand-alone JavaScript.

<SCRIPT LANGUAGE="JavaScript" RUNAT="Server">
function JSGreeting()
	{
	return "Greetings from a JavaScript Function";
	}
</SCRIPT>

This looks like any simple JavaScript you might find on the client side except for this little number: RUNAT="Server".

The RUNAT attribute tells the server to execute on the server, so the client never sees it. You can also set RUNAT="Client" in which case the Script would be passed along as-is to the web browser.

By the way, <SCRIPT LANGUAGE="JavaScript" RUNAT="Server"> should NOT be put inside ASP flags.

Take a look at the VBScript directly below.

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Function VBGreeting()
	VBGreeting="Greetings from a VBScript Function"
End Function

This VBScript does exactly the same thing as its JavaScript counterpart. There's nothing terribly special about it.

The Invocation:

There is, however, something special about the following VBScript.

Function toDollars(x)
	toDollars=FormatCurrency(x)
End Function

The above function will take an argument from a JavaScript Function. Then it will return the appropriate value to the JavaScript function. Let me show how Function toDollars(x) is invoked.

function add(x,y)
	{
	result = x + y;
	result = toDollars(result);
	return result;	
	}

function add(x,y) is a JavaScript function. Halfway into the function, there is the following line:

result = toDollars(result);

The above line is in fact a call from a JavaScript function to invoke a VBScript function. How about that!

Warning:

Just one caveat. When you create scripts using the RUNAT attribute there is in fact an order of execution. I won't go into it now, because the order of execution is situational.

Here's what I will get into: Use scripts with the RUNAT attribute only for functions (and those global variables called inside functions). DON'T put top level code into it. You have no guarantee that top level code will execute in order using this technique.

相关文章推荐

Using VBScript to Send Emails with Gmail

I normally don’t post scripts and batch files that I use, but I wanted to share this particular scri...

Create Ms Word doc using Javascript And vbscript

Create Ms Word doc using Javascript var app =new ActiveXObject('Word.Application');// var ob...

Create Ms Word doc using Javascript And vbscript .

'Geovin Du Set objWord = CreateObject("Word.Application") objWord.Caption = "Test Caption" objWord.V...

Quartz.NET教程_Lesson 1: Using Quartz

Lesson 1: Using Quartz 课程1:使用Quartz Before you can use the scheduler, it needs to be instantiated...

log4net 使用示例|using log4net with asp.net/winform

log4net, 是 apache.org 在 log4j的基础上推出的针对.NET程序的开源的日志组件。log4net目前的最新版本是 1.2.10,log4net支持的日志保存方式,可谓丰富之极,...

[初学 Unity]Graphics-04.Using Cameras && Using Lights && Fun with Lasers

Using CamerasIn this session you will learn the basics of the Unity camera system. You will learn ab...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)