好吧,我是第一次接触asp/vbscript世界。我在一家新公司工作,正在尝试复制我在php.I下开发时在几乎所有项目中都使用的脚本,我有两个函数,一个叫showHeader,一个叫showFooter。这些函数都获得传递给它们的参数,这些参数需要显示在包含的文件中。例如,在php中,我的showHeader函数如下所示
<?php
showHeader($page,$title,$passedCSS,$desc,$keywords) {
include("header.php");
}
?>现在,在包含文件中,我只需调用echo $var就可以回显出这些参数中的任何一个的内容,然后我就可以获得这些内容。这可以用vbscript实现吗?我没什么好运气的。
发布于 2011-03-18 04:07:26
好的,这就是我所做的
global.asp
<%@LANGUAGE="VBSCRIPT"%>
<%
Sub showHeader(page,title,passedCSS,desc,keywords)
%>
<!---#include file="header.asp"--->
<%
end Sub
Sub showFooter(passedJS)
%>
<!---#include file="footer.asp"--->
<%
end Sub
%>然后在header.asp和footer.asp中,我只使用<%=varname%>传入了var
然后在main.asp中,我的代码如下所示。
<!---#include file="global.asp"--->
<% showHeader "Home","Test Page","test.css","Description","keywords" %>
<section>
</section>
<aside>
</aside>
<section>
<h2></h2>
<ul>
<li><article></article></li>
<li><article></article></li>
</ul>
</section>
<section>
<div></div>
<div></div>
<div></div>
</section>
<% showFooter "testjs.js" %>一切都运行得很好。
发布于 2011-03-16 02:47:39
@projectxmatt:你可以这样做--
在header.asp中
<%
Sub showHeader(page, title, passedCSS, desc, keywords)
%>
<!-- some HTML code here -->
<title><%=page %></title>
<!-- more HTML code here -->
<%
End Sub
%>在somefile.asp中
<!-- #include file="header.asp" -->
<% showHeader "value-for-page", "My Page Title", "", "", "" %>在ASP中,你必须指定你的Sub或Function中的所有变量,如果没有传递给函数(例如function showHeader(title = 'Default Value')),它们就不能像在PHP中那样被省略或赋值为默认值。
发布于 2011-03-16 02:50:26
Response.Write是另一种解决方案,你可以用它来编写经典的ASP.
https://stackoverflow.com/questions/5316013
复制相似问题