我需要使用jQuery效果来显示或隐藏div。但是,在执行以下任何方法后,我在控制台中收到错误。
动画第一次完成,但在动画完成后,Safari控制台中会显示错误,我无法再在同一个div上应用任何其他jquery方法。
我确信这是由于其他一些代码在应用程序中搞乱,因为以下代码在jsfiddle中工作正常。
$('#testDiv').slideDown()
$('#testDiv').slideUp()
$('#testDiv').show('slow')
$('#testDiv').hide('slow')
$('#testDiv').toggle('slow')
错误
TypeError: 'undefined' is not a function (evaluating 'c.replace(bo,"-$1")')
元素
<div id='testDiv'>text</div>
答案 0 :(得分:1)
鉴于这些陈述(所有引用):
the console doesn't show any error when using $('#testDiv').show() or $('#testDiv').hide()
this works fine when checking with a test html page or in jsfiddle.
the error occurs only in my project
The jquery library file is unaltered
以下是我的想法:
show('slow')和hide('slow')已在jQuery-1.0中引入。
可以提供字符串'fast'和'slow',分别表示持续时间为200和600毫秒。
在javascript中,任何内容(几乎)都可以是变量名称:
在许多情况下,许多库使用$
符号,它在jQuery版本中更受欢迎,因此一些库可以使用相同的$
。
在jQuery中,$
符号是jQuery
的简写。
我的建议:
确保jQuery是要加载的最后 js文件,只是为了检查是否有其他javascript文件覆盖了jQuery的某些功能。如果jQuery现在有效,那么它被另一个javascript文件覆盖。
然后以权威性解决方案执行此操作:
执行$.noConflict();
哪个会将$
释放给使用它的其他图书馆并开始使用jQuery
代替$
。
This fiddle适用于jquery-1.0.1
(找不到1.0),这里是javascript代码:
$(function() {
$('button#hideSlow').click(function() { $('p#hello').hide('slow'); });
$('button#showSlow').click(function() { $('p#hello').show('slow'); });
});
资源:
答案 1 :(得分:0)
发现Json库弄乱了jQuery 1.6.4
https://github.com/douglascrockford/JSON-js/blob/master/json2.js
用JSON.strigify()替换了toJSONString(),这个错误消失了。