このデモを参照してください:
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>