javascript代码不工作ie7 ie8

时间:2012-12-15 12:09:17

标签: javascript

这是我的代码,它正在使用ie9 chrome firefox,但ie7和ie8无效:(

html代码

<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">';
}

1 个答案:

答案 0 :(得分:1)

这应该有效,

HTML

<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


});​