使用 Scriptaculous 时未定义效果

发布于 2024-08-20 11:24:36 字数 1468 浏览 3 评论 0原文

看来我错误地安装了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多情出卖 2024-08-27 11:24:36

您需要将

<html>

<head>
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/scriptaculous.js" type="text/javascript"></script>
</head>

<body>

<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>

这应该可以解决问题。

You need to put the <script> definitions in the <head> of your HTML document like this:

<html>

<head>
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/scriptaculous.js" type="text/javascript"></script>
</head>

<body>

<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>

That should do the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文