jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jQuery效果返回undefined大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下块:

$('.new_comment').live('ajax:success',function(evt,data,status,xhr){
  $('.comments article:last').after(xhr.responseText).effect("highlight",{},3000);
})

因此,当提交new_comment表单时,它会调用它.

after()函数工作正常,但是effect()调用抛出了这个错误

TypeError: 'undefined' is not a function (evaluaTing '$('.comments article:last').after(xhr.responseText).effect("highlight",3000)')

我正在使用jQuery 1.7.1和jQuery UI 1.8.16.

更新:xhr.responseText返回一个新创建的文章元素,如下所示:

<article id="2">
  <h6><a href="#">Joe</a> <span>(<a href="#2">less than a minute ago</a>)</span></h6>
  <p>This is the new comment!</p>
</article>

添加之后,.comments DOM看起来像这样

<section class="comments">
  <h3>Comments</h3>
  <article id="1">
    <h6><a href="#">Joe</a> <span>(<a href="#1">less than a minute ago</a>)</span></h6>
    <p>This is a comment!</p>
  </article>
  <article id="2">
    <h6><a href="#">Joe</a> <span>(<a href="#2">less than a minute ago</a>)</span></h6>
    <p>This is the new comment!</p>
  </article>
</section>

另外,如果我运行console.log($(‘.comments article:last’));,它肯定会返回创建的对象.

解决方法

解决了这个问题.我两次加载jQuery库.一旦使用预先捆绑的版本与Rails和一次使用谷歌的CDN.删除其中一个,现在一切正常.叹.

大佬总结

以上是大佬教程为你收集整理的jQuery效果返回undefined全部内容,希望文章能够帮你解决jQuery效果返回undefined所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。