0

我有两个文件 A.asp 和 B.asp 。B.asp 包含我想在 A.asp 中使用的长 javascript 函数。为了包括它,我使用了:

<!--#include file="lib/B/B.asp"-->

...在 A.asp 的头部我补充说:

<script>

函数使用(){

try{
    test = new FPDF();
}catch(err){
    document.write(err);
}

}

new FPDF() 是对 B.asp 文件中函数 FPDF() 的对象引用,如下所示:

<script>
function FPDF(){
var x;
this.x = function x(){
...
}

}
</script>

我收到一条错误消息:“ReferenceError:FPDF 未定义”...我该如何正确执行此操作?我想做的是像这样调用 FPDF() 中的函数:

<script>

函数使用(){

try{
    test = new FPDF();
            test.x();               //!!!!
}catch(err){
    document.write(err);
}

}

4

2 回答 2

0

Create an external javascript file like (myscript.js) and keep all your javascript code there.In a.asp reference that javascript file similary in b.asp reference the same javascript file.

Example --- in a.asp

<html>
<head></head>

<body>

 <script src="/myscript.js"></script>
</body>

</html>

Simiraly in b.asp-----

<html>
<head></head>

<body>

 <script src="/myscript.js"></script>
</body>

</html>
于 2013-11-03T18:37:13.407 回答
0

"runat=server" 指令正是这样做的,它告诉服务器执行代码,而不是按原样提供代码以供 Web 浏览器解释。给你一个非常简单的例子:

<html>
<head>
<script language="Jscript" runat="server">
  var helloworld = "Hello World";
</script>
</head>
<body>
<%= helloworld %>
</body>
</html> 

当请求此页面时,服务器将向浏览器发送以下内容

<html>
<head>
</head>
<body>
Hello World
</body>
</html>

所以你的onclick按钮不起作用的原因是它可以看到的页面上没有JS。如果要将变量发送到服务器端函数,则需要将它们以表单的形式发布到页面,然后使用 Request.Form 检索它们。

我希望这有帮助

于 2013-11-09T13:11:26.923 回答