0
这应该很简单 - 不要弄错我做错了!这是一个非常基本的测试(我是新来的PERL和JavaScript) - 这是CGI文件:从Perl调用Javascript函数
#! /usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<html>\n" ;
print "<head>Hello\n";
print '<script type="text/javascript" language="javascript" src="wibble.js">\n';
print "</script>\n";
print "</head>\n";
print "<body>\n";
$fred = "Fred";
$numb = 7;
print <<TEST;
<p>Starting...</p>
<p><script type="text/javascript" language="javascript">
theText = "$fred";
theNum = "$numb";
document.writeln("Direct write...");
document.writeln("Number is: " + theNum);
document.writeln("Text is: " + theText);
testWrite(theNum, theText);
</script></p>
<p>...ending JS</p>
TEST
和wibble.js:
function testWrite(num1, txt1)
{
document.writeln("In testWrite...");
document.writeln("Number is: " + num1);
document.writeln("Text is: " + txt1);
}
在我的浏览器,我得到的第一套writeln的,但我的功能从来没有被调用过。网页上的错误显示第15行('print <<TEST'
行)处的'Object expected'。
我主要怀疑我的src元素没有找到正确的路径,但我尝试了所有我能想到的组合('。','./',完整路径等) - 没有任何作用。 js文件与CGI文件位于相同的目录中。 (我实际上最初有没有参数的函数调用,希望theNum和theText是全局的并且仍然能够工作(这是这个测试程序的原始点))。
请把我从我的痛苦......
按照要求,这里是从浏览器源代码:
<html>
<head><script type="text/javascript" language="javascript" src="wibble.js"></script>
</head>
<body>
<p>Starting...</p>
<p><script type="text/javascript" language="javascript">
theText = "Fred";
theNum = "7";
document.writeln("Direct write...");
document.writeln("Number is: " + theNum);
document.writeln("Text is: " + theText);
testWrite(theNum, theText);
</script></p>
<p>...ending JS</p>
</body>
</html>
,这是网页上的实际输出:
Starting...
Direct write... Number is: 7 Text is: Fred
...ending JS
单引号的字符串不能将'\ n'理解为换行符。检查脚本的输出。我除了在'