[英]enable disable image button
这是我正在尝试做的事情,是的,我已经浏览了这个网站寻找答案,但我仍然迷失了。 我需要帮助的是我正在为Android和IOS(IPAD,IPHONE,ITOUCH)设备制作游戏菜单。 菜单上会显示文字图片或纯文字。 红色按钮被禁用,绿色按钮启用,例如,如果红色显示,您可以在后台听到音乐播放,如果您单击它并显示绿色,则音乐将不再通过游戏播放。 对于跳过功能也是如此,它将启用/禁用这些功能。 希望在javascript中执行此操作。 任何建议都会有所帮助,谢谢。
由于网站规则我无法发布图片。 我会把它写在菜单上。 图像=(红色)(绿色)
音乐(红色)(绿色)
跳过(红色)(绿色)
看这个演示:
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.