开发者

Creating an ON/OFF button with javascript [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it ca开发者_如何学运维n be reopened, visit the help center. Closed 11 years ago.

Place a single button on a page that could be used as an ON/OFF switch. Design this button so that the button is labeled "ON". When you click on the button its label should change to "OFF". Clicking on it again should change it back to "ON" and so on.


This ok?:

<script type="text/javascript">
function onoff(){
  currentvalue = document.getElementById('onoff').value;
  if(currentvalue == "Off"){
    document.getElementById("onoff").value="On";
  }else{
    document.getElementById("onoff").value="Off";
  }
}
</script>

<input type="button" value="On" id="onoff" onclick="onoff();">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜