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

ako*_*win 4 html javascript php 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();

}
Run Code Online (Sandbox Code Playgroud)

的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>
Run Code Online (Sandbox Code Playgroud)

Fel*_*lix 5

您需要将您<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>
Run Code Online (Sandbox Code Playgroud)

此外,由于您使用的是jQuery版本1.11并且.live()已在版本中删除1.9,因此您需要使用.on(),因此您可以更改:

$('#growl').find('.close').live('click', function(){ .....
Run Code Online (Sandbox Code Playgroud)

至:

$('#growl').find('.close').on('click', function(){ .....
Run Code Online (Sandbox Code Playgroud)

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

最后要注意的是,您只需要包含一次jQuery而不是两次,就像您现在正在做的那样.