<div id="audio-player">
<div>
<img id="playButton"
onclick="document.getElementById('stars').play();
document.getElementById('playButton').toggle(
function(){ $(this).attr("src", "playbutton-active.png"); },
function(){ $(this).attr("src", "playbutton-inactive.png"); } );"
src="playbutton-inactive.png">
<img id="pauseButton"
onclick="document.getElementById('stars').pause();
document.getElementById('pauseButton').toggle(
function(){ $(this).attr("src", "pausebutton-active.png"); },
function(){ $(this).attr("src", "pausebutton-inactive.png"); } );"
src="pausebutton-inactive.png">
<img id="stopButton"
onclick="document.getElementById('stars').pause();
document.getElementById('stars').currentTime = 0;
documen开发者_Python百科t.getElementById('stopButton').toggle(
function(){ $(this).attr("src", "stopbutton-active.png"); },
function(){ $(this).attr("src", "stopbutton-inactive.png"); } );"
src="stopbutton-inactive.png">
</div>
<audio id="stars">
<source src="stars-in-the-night-sky.mp3">
<source src="stars-in-the-night-sky.ogg">
</audio>
I also tried instead of getElementById('playButton'), using $(this).toggle but active/inactive images don't toggle. When I don't have the toggle statements, the custom buttons work to start/pause/stop audio. Adding the toggle, the controls no longer function, though the initial inactive control images show up. I realize also that I would need a separate function to reset the other buttons when one is toggled.
You should try "$("#playButton").toggle(..);". You need to have a JQuery object...
Use this method, instead:
<script type="text/javascript">
$(document).ready(function(){
$("#playButton").click(function(){
$(this).toggle(..);
});
});
</script>
You can see also JQuery-ui and its"button" method!
精彩评论