Creating an ON/OFF button with javascript [closed]
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();">
精彩评论