使用 Scriptaculous 时未定义效果
看来我错误地安装了 Scriptaculous,但我不知道出了什么问题。下面是一个显示问题的示例:
<html>
<body>
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/scriptaculous.js" type="text/javascript"></script>
<p id="hello">Hello, World!</p>
<a href="javascript:void(0)" onclick="Effect.Shrink('hello');">Shrink effect</a>
<a href="javascript:void(0)" onclick="$('hello').shrink();">Shrink method</a>
</body>
</html>
当我单击“缩小效果”链接时,出现 Javascript 错误“效果未定义”。当我单击“Shrink method”链接时,出现不同的错误:“$("hello").shrink 不是函数。”
如果我显式链接到效果脚本,问题就会消失:
<html>
<body>
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/scriptaculous.js" type="text/javascript"></script>
<script src="js/effects.js" type="text/javascript"></script> <!-- Added -->
<p id="hello">Hello, World!</p>
<a href="javascript:void(0)" onclick="Effect.Shrink('hello');">Shrink effect</a>
<a href="javascript:void(0)" onclick="$('hello').shrink();">Shrink method</a>
</body>
</html>
此解决方法是可以接受的,但 Scriptaculous 不能自动加载其所有帮助程序脚本吗?似乎安装说明说它应该。
我的 html 文件和 js 文件夹不在 Web 服务器的根文件夹中,它们都在应用程序文件夹下。我在 Firefox 3.5.7 和 Internet Explorer 8.0 中看到了相同的行为。
It seems I've installed Scriptaculous incorrectly, but I can't figure out what's wrong. Here's a sample to show the problem:
<html>
<body>
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/scriptaculous.js" type="text/javascript"></script>
<p id="hello">Hello, World!</p>
<a href="javascript:void(0)" onclick="Effect.Shrink('hello');">Shrink effect</a>
<a href="javascript:void(0)" onclick="$('hello').shrink();">Shrink method</a>
</body>
</html>
When I click on the "Shrink effect" link, I get a Javascript error, "Effect is not defined." When I click on the "Shrink method" link, I get a different error, "$("hello").shrink is not a function."
The problem goes away if I explicitly link to the effects script:
<html>
<body>
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/scriptaculous.js" type="text/javascript"></script>
<script src="js/effects.js" type="text/javascript"></script> <!-- Added -->
<p id="hello">Hello, World!</p>
<a href="javascript:void(0)" onclick="Effect.Shrink('hello');">Shrink effect</a>
<a href="javascript:void(0)" onclick="$('hello').shrink();">Shrink method</a>
</body>
</html>
This workaround is acceptable, but can't Scriptaculous load all its helper scripts automatically? It seems like the installation instructions say that it should.
My html file and the js folder are not in the web server's root folder, they're both under an application folder. I see the same behaviour in Firefox 3.5.7 and Internet Explorer 8.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将
定义放入 HTML 文档的
中,如下所示:
这应该可以解决问题。
You need to put the
<script>
definitions in the<head>
of your HTML document like this:That should do the trick.