我正在「計算器」(遊戲)上單擊「輸入」按鈕,數字自動添加在「總計」輸入中。但是 - 我需要三個(或更多)「Total」Windows。我想通過一個單選按鈕來更換你正在使用的「Total Window」。Javascript swapable calculated field
我使用一個「總窗口」工作 - 但我不確定如何交換正在計算中使用的字段。
可能是一些簡單的 - 但我是新來的JavaScript和語法...
<script language="javascript" type="text/javascript">
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function BetWIN(form) {
var MyField = eval(form.InputWIN.value)
}
function BetPLACE(form) {
var MyField = eval(form.InputPLACE.value)
}
function BetSHOW(form) {
var MyField = eval(form.InputSHOW.value)
}
function a_plus_b(form) {
a=eval(form.MyField.value)
b=eval(form.b.value)
z=a+b
form.MyField.value = z
}
function a_plus_c(form) {
a=eval(form.MyField.value)
c=eval(form.c.value)
z=a+c
form.MyField.value = z
}
function a_plus_d(form) {
a=eval(form.MyField.value)
d=eval(form.d.value)
z=a+d
form.MyField.value = z
}
function a_plus_e(form) {
a=eval(form.MyField.value)
e=eval(form.e.value)
z=a+e
form.MyField.value = z
}
function a_plus_f(form) {
a=eval(form.MyField.value)
f=eval(form.f.value)
z=a+f
form.MyField.value = z
}
function a_plus_g(form) {
a=eval(form.MyField.value)
g=eval(form.g.value)
z=a+g
form.MyField.value = z
}
function a_plus_h(form) {
a=eval(form.MyField.value)
h=eval(form.h.value)
z=a+h
form.MyField.value = z
}
// End -->
</script>
<FORM NAME="Calc">
<TABLE BORDER=4>
<TR>
<TD align="center"></TD>
<TD align="center"><input type="radio" name="BetSelector" value="InputWin" onclick="BetWIN(this.form)" checked="checked" /> WIN<br /><INPUT TYPE="text" NAME="InputWIN" Size="16" value="0" /></TD>
<TD align="center"><input type="radio" name="BetSelector" value="InputPLACE" onclick="BetPLACE(this.form)" /> PLACE<br /><INPUT TYPE="text" NAME="InputPLACE" Size="16" value="0" /></TD>
<TD align="center"><input type="radio" name="BetSelector" value="InputSHOW" onclick="BetSHOW(this.form)" /> SHOW<br /><INPUT TYPE="text" NAME="InputSHOW" Size="16" value="0" /></TD>
</TR>
<tr>
<td colspan="4">
<INPUT TYPE="button" NAME="b" VALUE="1" OnClick="a_plus_b(this.form)" class="ChipB">
<INPUT TYPE="button" NAME="c" VALUE="5" OnCLick="a_plus_c(this.form)" class="ChipC">
<INPUT TYPE="button" NAME="d" VALUE="25" OnClick="a_plus_d(this.form)" class="ChipD">
<INPUT TYPE="button" NAME="e" VALUE="100" OnClick="a_plus_e(this.form)" class="ChipE">
<INPUT TYPE="button" NAME="f" VALUE="500" OnCLick="a_plus_f(this.form)" class="ChipF">
<INPUT TYPE="button" NAME="g" VALUE="1000" OnClick="a_plus_g(this.form)" class="ChipG">
<INPUT TYPE="button" NAME="h" VALUE="5000" OnClick="a_plus_h(this.form)" class="ChipH">
</td>
</tr>
</TABLE>
</FORM>
我開始的jsfiddle:http://jsfiddle.net/bigfatdesigns/eSAPk/
evaaaaaaaaaaaaaaaaal! – elclanrs
[Eval is evil](http://javascriptweblog.wordpress.com/2010/04/19/how-evil-is-eval/) – Zack
是的 - 我是js noob ....我建立了這個引用其他代碼 - 沒有意識到eval的罪惡......? –