2012-11-04 38 views
2

我用JQuery Mobile調用servlet時遇到了問題。使用iPhone我注意到servlet SendMp3Servlet在列表條目上被單擊6次被調用。使用Chrome的桌面版本,servlet只能被正確調用一次。有人可以幫我找到問題嗎?JQuery手機iPhone點擊通話servlet 6次

下面是代碼:

<!DOCTYPE html> 
<html> 
<head> 
    <title>Canzoni</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /> 
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script> 
    <script src="popola_liste.js"></script> 
</head> 
<body> 
    <script > 

    </script> 
    <div data-role="page"> 

     <div data-role="header" > 
      <a href="Album.html" data-rel="back">back</a> 
      <h1>Project ML</h1> 
     </div> 

     <div data-role="content"> 
      <ul id="listviewSong" data-role="listview" data-inset="true" data-filter="true"> 
       <script>$.getJSON("GestoreCanzoni?idAlbum="+sessionStorage.getItem("idAlbum"), function(data){ 
        var output = ''; 

        $.each(data, function(index, value){ 
         output += '<li><a href="#" onclick="sessionStorage.setItem(\'idCanzone\',\''+value.id+'\');"> ' + value.nome + '</li>'; 
        }); 

        $('#listviewSong').append(output).listview('refresh'); 

        var event = (navigator.userAgent.match(/iPhone|iPad/i)) ? 'touchstart' : 'click'; 
        $('#listviewSong').unbind(event).bind(event,function(e){ 
         alert("c"); 
         update_player(); 
        }); 

       });</script> 
      </ul>  
     </div><!-- /content --> 

     <div data-role="footer" data-position="fixed" data-id="player"> 
      <audio id="player_audio" controls="controls"> 
       <source id="src_player" src="sessionStorage.getItem('request_mp3')" type="audio/mpeg" /> 
      </audio> 
     </div> 

    </div> 

</div><!-- /page --> 

</body> 
</html> 

這就是所謂的點擊js函數:

function update_player(){ 
     lastIdCanzone=sessionStorage.getItem("idCanzone"); 
     var id=sessionStorage.getItem('idCanzone'); 
     sessionStorage.setItem('request_mp3','/Libreria_musicale_server/SendMp3Servlet?idCanzone='+id); 
     document.getElementById("src_player").src="/Libreria_musicale_server/SendMp3Servlet?idCanzone="+id; 
     document.getElementById("player_audio").load(); 
     document.getElementById("player_audio").play(); 
} 

回答

0

jQuery Mobile的是有點棘手... 首先,爲什麼不你使用jQuery手機事件,如:(點擊,點擊....) 而不是JavaScript onclick事件。

另一件事是,iPhone上的jQuery的移動有時會點擊事件兩次, 所以儘量使用水龍頭。