我会尽我所能解释它。我使用Javascript中的按钮(红色右侧),所以当我点击每个按钮时,它们变成绿色,当我再次点击它们时,它们变成红色。我试图让图像按钮(左侧)工作,如果我点击每一个它会转动javascript按钮(红色右侧)。这意味着我可以使用任何一个来启用/禁用。image to javascript button
这里是图像:
HTML代码:
<img src="images/menuIcons/skip.gif" width="126" height="34" />
<div align="center" style="margin-bottom: 10px; margin-left: 10px;">
<button id="skip" class="red" onclick="controls(this.getAttribute('class'),this.id)"></button>
<img src="images/menuIcons/text.gif" width="126" height="34" />
<div align="center" style="margin-bottom: 10px; margin-left: 10px;">
<button id="text" class="red" onclick="controls(this.getAttribute('class'),this.id)"></button>
<img src="images/menuIcons/message.gif" width="126" height="34" />
<div align="center" style="margin-bottom: 10px; margin-left: 10px;">
<button id="message" class="red" onclick="controls(this.getAttribute('class'),this.id)"></button>
<img src="images/menuIcons/game.gif" width="126" height="34" />
<div align="center" style="margin-bottom: 10px; margin-left: 10px;">
<button id="game" class="red" onclick="controls(this.getAttribute('class'),this.id)"></button>
Javascript代码:
// enable/disable Buttons
function controls(className,elem) {
if (className == "red") {
document.getElementById(elem).setAttribute('class','green');
// You can define your enable statements here
} else {
document.getElementById(elem).setAttribute('class','red');
// You can define your disables statements here
}
}
究竟是什么问题?你只是想能够点击一个按钮并将其变为绿色,然后再次点击将其变回红色? – 2012-08-04 22:44:35
@ChrisClower我相信他希望能够点击按钮旁边的文本来触发按钮。所以他有一个“按钮”有两个“开关”。 – Kiruse 2012-08-04 22:50:26
我已将它设置为当您单击红色圆圈时它变为绿色,并且您再次单击它时会回到红色。这工作正常。我的问题是,如何在图像左侧制作图像按钮,当我点击它们时,红色按钮变成绿色,而当我再次点击按钮时,图像按钮变回红色。 – akamerc 2012-08-04 22:52:30