相关,但不是修复:jQuery issue - #<an Object> has no method
当我尝试在 jquery 中使用 effect
函数时,出现错误 Object [object Object] has no method 'effect'
(doc http://docs.jquery.com/UI/Effects/Highlight ) 。它在 JSFiddle 中工作正常,但当我在 Chrome 或 IE 中运行该网站时出现错误。 div 已显示,但效果调用抛出错误。
实时版本可以在这里找到:http://jsfiddle.net/jcollum/HK625/
HTML
<a id=showHowThisWorks >How does this all work?</a>
<div id="howThisWorks" style="display: none; ">
<p>It works fine</p>
</div>
还有这个 CoffeeScript :
$(document).ready ->
$('#howThisWorks').hide()
$('#showHowThisWorks').click ->
$div = $('#howThisWorks')
$div.toggle();
$div.effect("highlight", {}, 10000)
return
return
在 JS 中看起来像这样:
$(document).ready(function() {
$('#howThisWorks').hide();
$('#showHowThisWorks').click(function() {
var $div;
$div = $('#howThisWorks');
$div.toggle();
$div.effect("highlight", {}, 6000);
});
});
我尝试使 $div 成为该行上的 jquery 选择器,而不是使用变量。我尝试过将 $div 包装在 $() 中。我在页面的真实版本上仍然收到错误。 Chrome 和 IE9 中的结果相同。显然我错过了有关 jquery 对象行为方式的一些内容。
最佳答案
我相信 jQuery UI 没有在本地部署:检查 Firebug/Chrome 等进行验证。
.toggle()
是核心 jQuery 的一部分,.effect()
是 jQuery UI 的一部分:为了使其不起作用,jQuery UI 不得出席。
关于jquery - “effect”在 jsfiddle 中工作正常,但在实时代码中不起作用([object Object] 没有方法 'effect' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8114357/