最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught TypeError: Object [object Object] has no method 'apply' - Stack Overflow

programmeradmin5浏览0评论

I am receiving this Uncaught TypeError on a new website I am creating, but I can't work out what is causing the error.

I have recreated the issue at the link below, if you take a look at your browsers JS console you'll see the error occurring, but nothing else happens.

/

Code:

$('.newsitem').hover(
$(this).children('.text').animate({ height: '34px' }), 
$(this).children('.text').animate({ height: '0px'  }));​

I am receiving this Uncaught TypeError on a new website I am creating, but I can't work out what is causing the error.

I have recreated the issue at the link below, if you take a look at your browsers JS console you'll see the error occurring, but nothing else happens.

http://jsfiddle/EbR6D/2/

Code:

$('.newsitem').hover(
$(this).children('.text').animate({ height: '34px' }), 
$(this).children('.text').animate({ height: '0px'  }));​
Share Improve this question edited Jun 15, 2012 at 5:12 pb2q 59.6k19 gold badges150 silver badges152 bronze badges asked Jun 14, 2012 at 12:03 David PooleyDavid Pooley 811 gold badge1 silver badge8 bronze badges 2
  • Where is .text in the HTML? – gdoron Commented Jun 14, 2012 at 12:04
  • sorry, that should have read .title – David Pooley Commented Jun 14, 2012 at 12:17
Add a ment  | 

4 Answers 4

Reset to default 5

Be sure to wrap those in asynchronous callbacks:

$('.newsitem').hover(
    function() {
        $(this).children('.title').animate({height:'34px'});
    }, function() {
        $(this).children('.title').animate({height:'0px'});
    }
);
​

You need:

.hover(function(){ ... });

as per the documentation.

You're missing the function...

$('.newsitem').hover(
    $(this).children('.text').animate({height:'34px'}),
    $(this).children('.text').animate({height:'0px'})
);

To:

$('.newsitem').hover(function() {
    $(this).children('.text').animate({
        height: '34px'
    });
}, function() {
    $(this).children('.text').animate({
        height: '0px'
    });
});​
​

And the ​$(this).children('.text'), is not selecting anything.

use slide animation to handle hight of the .text class.

$('.newsitem').hover(function() {
    $(this).children('.text').slideToggle();
});​
​
发布评论

评论列表(0)

  1. 暂无评论