2012-12-15 100 views
0

這是我的代碼,它的工作在IE9鉻火狐但IE7和IE8不工作:(javascript代碼不工作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

什麼錯誤,你好嗎? – ajtrichards

+2

'document.getElementById('pp')。html ='?這是什麼 ? –

+0

也可能是$(selector).html()的比較, –

回答

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 


});​ 
+0

非常感謝 –