论坛: 网站建设 标题: 请教关于VBScript和JScript的一个小问题 复制本贴地址    
作者: Aoming [aoming]    版主   登录
请问内容为如下代码的.asp文件,在正常执行后在浏览器中得到的结果是什么?
----------------------------------------------
<html>
<head><title>ASP Script示例</title></head>
<body>
This is the first sentence
<script LANGUAGE="VBScript" RUNAT="server">
response.write("This is the second sentence.")
</script>
</body>
</html>
--------------------------------------------------

地主 发表时间: 04-02-09 13:05

回复: Aoming [aoming]   版主   登录
接着请告之这段JScript的运行结果,条件同上
---------------------------------------------
<html>
<head><title>ASP Script示例</title></head>
<body>
This is the first sentence
<script LANGUAGE="JScript" RUNAT="server">
response.write("This is the second sentence.")
</script>
</body>
</html>
------------------------------------------------------

B1层 发表时间: 04-02-09 13:09

回复: newekin [newekin]      登录
1

This is the first sentence This is the second sentence.


2
This is the first sentence This is the second sentence.


B2层 发表时间: 04-02-09 14:47

回复: Aoming [aoming]   版主   登录

no
事实上结果应该是
1、This is the first sentence This is the second sentence
2、This is the second sentence. This is the first sentence

这里是第3段代码,执行.asp后可看到,先输出的是JScript一节的字符串,后输出的是VBScript一节的字符串
========== c.asp ==========
<html>
<head><title>ASP Script示例</title></head>
<body>
<script LANGUAGE="VBScript" RUNAT="server">
response.write("|这里是VBScript的输出|")
</script>
*TEST VBScript_JScript*
<script LANGUAGE="JScript" RUNAT="server">
response.write("_这是JScript的输出_")
</script>
</body>
</html>
==================================

通过查看经过服务端处理后返回到浏览器的html文件的源代码
======  c.asp => c.htm =============
这是JScript的输出.<html>
<head><title>ASP Script示例</title></head>
<body>

*TEST VBScript_JScript*

</body>
</html>
这里是VBScript的输出|.
============================
通过这3个例子,是否可以表明.asp文件中JScript脚本的执行是先于非脚本部分处理的,而VBScript是后于非脚本部分处理的?


[此贴被 Aoming(aoming) 在 02月09日18时09分 编辑过]

B3层 发表时间: 04-02-09 18:09

回复: newekin [newekin]      登录
你丫的耍我啊   

B4层 发表时间: 04-02-09 20:41

回复: Aoming [aoming]   版主   登录

no,没有没有,(我最多调戏and非礼你,嘿)。只是想用这样都可以直接看到结果的开始让大家参与下下,看能不能发现,或者多扯到一些话题,比如html语言不规范、设置ASP的脚本语言、用别的一些语言开发asp(比如perlscript等),最后一起讨论个东西出来

这个东西我是从《迈至科Active Server Pages在线技术手册》那个.chm文件“第四部分 创建Active Server Pages”――“第十三章 构建Active Server Pages”――“将Scripts(脚本语言)集成在Active Server Pages中”看到后想的,当时我在试Perlscript做脚本语言(没成功),于是想看看把JS改成VBS后还是不是这样,结果一改发现居然“置后显示”,参考资料有误,心里就有点想骂人的味道了:P

文章摘抄如下:

==============================================================================
如果你创建了一个客户端的VBscript或者JScript脚本,你就应当对<SCRIPT>更加熟悉了。微软的<Script>拓展可以被用来指定是在服务端还是在客户段执行。如果你忽略了RUNAT=server这个限定,你的script脚本将被认为是客户端的。这种场合下,Server端将忽略这个script并由浏览器尝试执行〔然而会很悲惨的以失败告终,因为这不是一个合法的客户端script脚本〕。

为什么你会直接使用<Script>对象而不是<%和%>来限定scipt脚本语言?通常,你不会使用<script>对象。不过,这两种限定一个Script脚本的方法还是有很明显的区别的。

首先,使用<script>包含的直接脚本会立即执行,无论在Active Server Pages的任何位置。例如下面这个例子。

<html>

<head><title>ASP Script示例</title></head>

<body>

This is the first sentence

<script LANGUAGE=“JScript” RUNAT=“server”>

response.write(“This is the second sentence.”)

</script>

</body>

</html>

看这个例子后,您也许会认为,显示器上会首先显示This is the first sentence,然后是This is the second sentence,但是,这个Active Server Pages显示在浏览器上是相反的顺序。(或者什么都不显示,那是因为生成了非法的HTML语法)

为什么会这样?因为主页里面无论什么放在<script>里面都会首先执行。如果你使用浏览器的View Source,你会看见你的主页被Active Server Pages解释为如下:

This is the second sentence.<html>

<head><title>ASP Script示例</title></head>

<body>

This is the first sentence.

</body>

</html>
====================================================================



B5层 发表时间: 04-02-10 01:54

回复: xiaoshi [xiaoshi]   论坛用户   登录
看了半天,只看懂了最后的一点 "asp与html的执行先后"
其他的还是有点晕!


B6层 发表时间: 04-02-10 03:42

论坛: 网站建设

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号