我怎麼能寫這個在JavaScript或jQuery的:
當我第一次onoff
VAR在change
功能得到值off
和off
按鈕變爲一個名爲on
按鈕,按下按鈕;
現在,當我按on
按鈕時,變量onoff
獲取值on
,並且該按鈕再次變爲off
按鈕。如何更改按鈕名稱和變量值?
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="jquery-min.js"></script>
<script type="text/javascript">
function change(inputId) {
/* ... do something with inputId ... */
var onoff = 'off';
console.log(onoff);
}
</script>
</head>
<body>
<form>
<table>
<tr>
<td>one:</td><td><input name="one" id="one" /></td>
<td><input type="button" id="b_one" value="off" onclick="change('one')"></td>
</tr>
<tr>
<td>two:</td><td><input name="two" id="two" /></td>
<td><input type="button" id="b_two" value="off" onclick="change('two')"></td>
</tr>
</table>
<br /><br /><input type="submit" value="ok"/></div><br />
</form>
</body>
</html>