<% %> 和有什么区别?和<脚本语言=“vbscript";runat=“服务器">在经典的asp? [英] what's the difference between <% %> and <script language="vbscript" runat="server"> in classic asp?

查看:17
本文介绍了<% %> 和有什么区别?和<脚本语言=“vbscript";runat=“服务器">在经典的asp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上找不到太多文档

到目前为止,明显的区别似乎是你不能使用script"标签混合html和vbscript

例如,这样就可以了

<上一页><% public sub display_literal() %>文字<% 结束子 %>

但你应该使用脚本标签

<上一页><脚本语言="vbscript" runat="服务器">公共子 display_literal2()response.write "literal2
"结束子

在这个页面上

http://www.newobjects.com/pages/ndl/alp/asp-structure.htm

它是这么说的

<块引用>

在经典 ASP 中,以页面的默认脚本语言(即 <% %> 标记所采用的语言)编写的脚本是第二个执行的 - 例如<% %> 标记中的所有脚本代码在所有 <SCRIPT RUNAT=SERVER ...> 脚本之后初始化.

但我做了几个测试,但无法验证...

我问是因为我有一个脚本(我现在手头没有)使用 <% %> 给了我一个错误,将其更改为 <script> 标记解决了问题,但是我想知道为什么....

无论如何,我想我们应该使用 <script> 标记来表示要从 <% %> 标记调用的函数和过程......对吗?

解决方案

首先你需要了解服务器端 script 标签的处理方式取决于是否指定了语言与页面的默认语言相同.

顺序是这样的:-

  1. 运行 <script runat="server" 标记中指定语言与默认语言不匹配的所有脚本.这些按文档顺序执行.
  2. 运行默认脚本.这意味着对页面中有静态内容的响应执行隐含的写入(不在 runat="server" 标记或 <% %> 内的内容) 以及 <% %> 中的任何中间代码显然再次按文档顺序排列.
  3. 在语言与默认脚本语言匹配的 <script runat="server" 标记中的全局级别运行任何代码.

请注意,所有脚本在执行阶段 1 之前都有一个初始解析,因此可能由阶段 3 中运行的脚本定义的任何函数都可用于从阶段 1 调用.

I couldn't find much documentation on the web

so far now, the obvious difference seems to be that you cant mix html and vbscript using the "script" tag

for example, this is ok

<% public sub display_literal() %>
  literal
<% end sub %>

but with the script tag you should


<script language="vbscript" runat="server">
public sub display_literal2()
    response.write "literal2</br>"
end sub
</script>

on this page

http://www.newobjects.com/pages/ndl/alp/asp-structure.htm

it says that

In classic ASP the script written in the default script language for the page (i.e. the language assumed for the <% %> tags) is executed second - e.g. all the script code in <% %> tags is initialized after all the <SCRIPT RUNAT=SERVER ...> scripts.

but I made a couple of tests and couldn't verify it...

I'm asking because I had a script (I don't have it at hand right now) that using <% %> gave me an error, changing it to the <script> tag solved the problem, but I'd like to know why....

anyway, I guess that we should use the <script> tag for functions and procedures that are to be called from <% %> tags... right?

解决方案

First off you need to understand that there's a difference in the way server-side script tags are handled depending on whether the language specified is the same as the default language for the page.

The order is this:-

  1. Run all scripts in <script runat="server" tags where the language specified does not match the default language. These are executed in document order.
  2. Run the default script. That means perform the implied writes to the response where there is static content in the page (the stuff not in runat="server" tags or inside <% %>) and any intervening code in <% %> again in document order obviously.
  3. Run any code at the global level found in <script runat="server" tags where the language matches the default script language.

Note that all script has an initial parse before executing phase 1, hence any functions that may be defined by scripts run in phase 3 will be available for calling from phase 1.

这篇关于&lt;% %&gt; 和有什么区别?和&lt;脚本语言=“vbscript";runat=“服务器"&gt;在经典的asp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆