看这个演示:
http://jsfiddle.net/rathoreahsan/xQ3PT/
Javascript代码
function controls(id) {
if (id == "play") {
document.getElementById('play').setAttribute('disabled','disabled');
document.getElementById('stop').removeAttribute('disabled','disabled');
// You can define your play music statements here
} else {
document.getElementById('stop').setAttribute('disabled','disabled');
document.getElementById('play').removeAttribute('disabled','disabled');
// You can define your stop music statements here
}
}
HTML 代码
Music <button id="stop" onclick="controls(this.id)" disabled="disabled">Stop</button> <button id="play" onclick="controls(this.id)">Play</button>
CSS
#stop{
background-color: red;
border: 0px;
}
#play{
background-color: green;
border: 0px;
}
编辑:
使用单个按钮的另一种解决方案:
演示:http: //jsfiddle.net/rathoreahsan/xQ3PT/2/
Javascript代码
function controls(className) {
if (className == "red") {
document.getElementById('PlayStop').setAttribute('class','green');
document.getElementById('PlayStop').innerHTML = "Stop";
// You can define your play music statements here
} else {
document.getElementById('PlayStop').setAttribute('class','red');
document.getElementById('PlayStop').innerHTML = "Play";
// You can define your stop music statements here
}
}
HTML 代码
Music <button id="PlayStop" class="red" onclick="controls(this.getAttribute('class'))">Play</button>