看起来我安装了错误的脚本,但我不知道哪里出了问题。下面是一个示例来说明这个问题:
<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错误,“效果未定义”。当我点击“收缩方法”链接时,我得到一个不同的错误,"$("hello").shrink不是一个函数。“
如果我显式链接到effects脚本,问题就会消失:
<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不能自动加载它的所有辅助脚本吗?看起来installation instructions说它应该这么做。
我的html文件和js文件夹不在web服务器的根文件夹中,它们都在应用程序文件夹下。我在Firefox3.5.7和Internet Explorer8.0中看到了同样的行为。
发布于 2010-02-05 09:58:55
您需要将<script>定义放在HTML文档的<head>中,如下所示:
<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>这应该能起到作用。
https://stackoverflow.com/questions/2202730
复制相似问题