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.

ASP学习笔记(4)--vbscript和javascript的混合使用

当然我们可以在一个asp文件中使用vbscript和javascript两中脚本语言。看下例   function jssayhello(){   return "hello world from j...
  • Jianghui1980
  • Jianghui1980
  • 2007年05月30日 15:35
  • 1087

ASP中JavaScript和VBScript混用与runat=server时脚本语言的执行优先级

 最近接触了一点ASP,虽然技术有点过时,但是我还是第一次使用,有必要总结一下最近碰到的一些问题。第一点,ASP中JavaScript和VBScript的混用问题。ASP中JavaScript和VBS...
  • loadsave
  • loadsave
  • 2008年03月11日 14:38
  • 1317

经典ASP开发:弃VBScript而选JScript的八大理由

我承认,我是 JS 服务端技术的鼓吹者,我企图将 JS 语言的应用“从客户端包围服务端”,况且这不是新鲜事(SSJS),与我保持同一意见的人应该是有的,尽管对此不会有太大的热情,或者没有为此而“雄辩”...
  • zhangxin09
  • zhangxin09
  • 2010年04月17日 15:52
  • 6092

vbscript和javascript之间的函数的调用

server1=cstr(request.servervariables("http_referer"))server2=cstr(request.servervariables("server_na...
  • iuhxq
  • iuhxq
  • 2004年12月06日 09:09
  • 1931

VBScript和JavaScript连接数据库(ACCESS)

1.VBScript连接数据库  程序代码 Dim conn,rs,sqlstr Set conn = CreateObject("ADODB.Connection") conn....
  • a771948524
  • a771948524
  • 2013年05月08日 16:28
  • 1996

javascript和php,asp区别

javascript是网络脚本语言,是在客户端浏览器上操作html标签 php和asp是服务端脚本语言 xml是为了存储数据、传送数据 html是为了数据的呈现,数据呈现外观。...
  • hitlisheng
  • hitlisheng
  • 2013年11月06日 20:29
  • 2990

javascript 与vbscript 互相调用

在 VBScript 的function 中可以直接编写 javascript 代码 但是只能返回一个字符串给变量 function clickEvent()name="www.blabla.cn"M...
  • liaomin416100569
  • liaomin416100569
  • 2010年06月14日 18:08
  • 1263

ASP VBscript使用逻辑运算中的 and or

if session("postTime") session("postTime")=NOW() response.write("postisfast") response.end end if 如果...
  • wang845252276
  • wang845252276
  • 2016年03月28日 13:32
  • 1151

续--sqlerror.cpp

#include "sqlerror.hpp"using namespace sqlpp;sqlerror::sqlerror(const std::string& code, const std::...
  • yi_jun_jun
  • yi_jun_jun
  • 2008年07月23日 17:34
  • 245

VBscript和javascript区别以及在哪里该用谁?

在很多论坛中看到关于VBscript和javascript到底应该使用哪个,哪个比较好的问题?  今天我来谈谈我的看法:  服务器端:  大家知道ASP支持这两中脚本语言,也就是在服...
  • Chair_
  • Chair_
  • 2014年10月31日 15:30
  • 1538
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Asp JavaScript 教程 - Lesson 04 Using VBScript with JavaScriptor
举报原因:
原因补充:

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