对象不支持此属性或方法.错误- JQuery


"Object doesn't support this property or method" error - JQuery

我有一个关于jquery咆哮通知的问题。我有这个错误在IE(我知道不是最好的选择来测试你的代码,但只是你的错误在javascript)"对象不支持此属性或方法".

notifyBidding.js

$(document).ready(function(){
    addNotice();
    setTimeout(function(){
    addNotice();
    },4000);        
$('#growl')
    .find('.close')
    .live('click', function(){
        $(this)
            .closest('.notice')
            .animate({
            border: 'none',
            height: 0,
            marginBottom: 0,
            marginTop: '-6px',
            opacity: 0,
            paddingBottom:0,
            paddingTop:0,
            queue:false
            },1000, function(){
                $(this).remove();
        });
        });
});
function addNotice(){
$('#growl')
.append($('<div id="bidTo"></div>').html($('<img id="bg2" src="notification.png" width="250" height="75"></img><p id="tag2">This item is about to end</p><img id="dp2" src="temporary.jpg"/><p id="bidTime" style="font-family:arial narrow; font-size:12; color:rgb(171,14,21); text-transform:uppercase; position:absolute; top:25px; left:85px"><b>about to end</b></p>')))
.hide()
.appendTo("#growl")
.fadeIn(1000)
.fadeOut(3000)
$('#bidTo').contents().unwrap();
}

welcome.php

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="design2.css"/>
        <script  type="text/javascript" src='script.js'></script>
    </head>
    <script type="text/javascript" src="jquery-1.11.0.min.js"></script>
    <script src="jquery-1.11.0.min.js"></script>
    <script src="jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js"></script>
    <script src="notification.js"></script>
    <script src="notifyBidding.js"></script>
<body>
<a id='imgCart' href='#'></a>

<div id='notification' >
    <img id='bg' src='notification.png' width='1110' height='65'></img>
    <p id='tag'>There are still &nbsp;&nbsp; in your shopping cart</p>
    <p id='noToPay'>5</p>
</div>
<div id='growl'></div>

</body>
</html>

您需要将您的<script>放在<head>部分或在关闭您的页面的</body>标记之前。

<head>
    <link rel="stylesheet" type="text/css" href="design2.css"/>
    <script  type="text/javascript" src='script.js'></script>
    <script type="text/javascript" src="jquery-1.11.0.min.js"></script>
    <script src="jquery-1.11.0.min.js"></script>
    <script src="jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js"></script>
    <script src="notification.js"></script>
    <script src="notifyBidding.js"></script>
</head>

另外,因为你使用的是jQuery版本1.11.live()已经在版本1.9中被删除,你需要使用.on()来代替,所以你可以改变:

$('#growl').find('.close').live('click', function(){ .....

:

$('#growl').find('.close').on('click', function(){ .....

除此之外,如果您的scripts.js使用jQuery或其他插件,您必须在包含jQuery和其他插件之后包含它。

最后要注意的是,你只需要包含jQuery一次,而不是像你现在所做的那样两次。