JavaScript代码不起作用IE7 IE8



这是我的代码,它可以在IE9 Chrome Firefox上运行,但IE7和IE8无法正常工作:(

网页代码

<ul class="controls">  
<li style="font-size: 10px; font-weight: bold; left: 310px; position: absolute; text-transform: uppercase; top: -102px;">
<a id="pp" href="#" title="" onclick="playPause()"><img src="../css/play.png"></a>
</li>
</ul>

JavaScript代码

var inter;
function playPause(){
if($('.controls li #pp').html() == '<img src="../css/play.png">'){
inter = setInterval(function() {
changeBannerImg(num,1);
}, 4600);
document.getElementById('pp').html = '<img src="../css/pause.png">';
}
else if($('.controls li #pp').html() == '<img src="../css/pause.png">'){
clearInterval(inter);
document.getElementById('pp').html = '<img src="../css/play.png">';
}   
}
function stopAni(){
clearInterval(inter);
document.getElementById('pp').html = '<img src="../css/play.png">';
}

这应该有效,

目录

<ul class="controls">  
  <li style="font-size: 10px; font-weight: bold; left: 310px; position: absolute; text-transform: uppercase; top: -102px;">
    <a id="pp" href="#" title=""><img src="../css/play.png"></a>
  </li>
</ul>

.JS

$(function() {
    var img = $('.controls li #pp img');
    function playPause() {
        if (img.attr('src').match(/play.png$/)) {
            inter = setInterval(function() {
                changeBannerImg(num, 1);
            }, 4600);
            img.attr('src', "../css/pause.png");
        } else if (img.attr('src').match(/pause.png$/)) {
            clearInterval(inter);
            img.attr('src', "../css/play.png");
        }
        return false;
    }
    function stopAni() {
        clearInterval(inter);
        img.attr('src', "../css/play.png");
    }
    img.parent().click(playPause);
//    other code here

});​

最新更新