菜鸟求个JS求和的问题 function znum(){input3.value=parseInt(input1.value)+parseInt(input2.value)}这样就可以了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 设置前两个文本框的 change 事件. 在事件中,重新计算和..并赋给第三个文本框. 这个不是蛮好弄的么?我看到这个js才牛。<html><body> <SCRIPT LANGUAGE="LiveScript"><!-- This Script Created by Chris Englmeier: http://www.geocities.com/SiliconValley/Heights/2052/ --><!-- For this and 100s of other Free Javascripts, check out: --><!-- Free-Javascripts.com @ http://www.free-javascripts.com/ --> <!-- step = 0; diff=3; // change board when button is clicked function clear_all(form) { step = 0; for (i=0;i<9; ++i) { position="a"+i; form[position].value=""; } } // change board when button is clicked function clickit(field) { if (step == -1) {alert("Reset to play again"); return;} position=field.name.substring(1,2,1); position = 'a'+position; if (field.form[position].value !="") {alert("Can't go there"); return;} field.form[position].value="X"; if (eval_pos(field.form)) { field.form.output.value="You Win!"; step = -1; return; } position=get_move(field.form); field.form.output.value='I moved to ' + position.substring(1,2,1); if (position=="") { field.form.output.value="No Winner."; step = -1; return; } field.form[position].value="O"; if (eval_pos(field.form)) { field.form.output.value="You Lose!"; step = -1; } } // see if there is a winner function eval_pos(form) { if ((form.a0.value!="" && form.a0.value==form.a3.value && form.a0.value==form.a6.value)|| (form.a0.value!="" && form.a0.value==form.a1.value && form.a0.value==form.a2.value) || (form.a0.value!="" && form.a0.value==form.a4.value && form.a0.value==form.a8.value) || (form.a1.value!="" && form.a1.value==form.a4.value && form.a1.value==form.a7.value) || (form.a2.value!="" && form.a2.value==form.a5.value && form.a2.value==form.a8.value) || (form.a2.value!="" && form.a2.value==form.a4.value && form.a2.value==form.a6.value) || (form.a3.value!="" && form.a3.value==form.a4.value && form.a3.value==form.a5.value) || (form.a6.value!="" && form.a6.value==form.a7.value && form.a6.value==form.a8.value)) return true; else return false; } function f(a) { if (a == "") return "."; else return a; } // get position for move. function comp_move(form,player,weight,depth) { var cost; var bestcost=-2; var position; var newplayer; if (player=="X") newplayer="O"; else newplayer="X"; if (depth==diff) return 0; if (eval_pos(form)) return 1; for (var i=0; i<9; ++i) { position='a'+i; if (form[position].value != "") continue; form[position].value=player; cost = comp_move(form,newplayer, -weight, depth+1); if (cost > bestcost) { bestcost=cost; if (cost==1) i=9; } form[position].value=""; } if (bestcost==-2) bestcost=0; return(-bestcost); } // get position for move. function get_move(form) { var cost; var bestcost=-2; bestmove=""; // don't think about first move. if (step++ == 0) if (form.a4.value=="") return "a4"; else if (form.a0.value=="") return "a0"; for (var i=0; i<9; ++i) { localposition='a'+i; if (form[localposition].value != "") continue; form[localposition].value="O"; cost=comp_move(form,"X", -1, 0); if (cost > bestcost) { if (cost==1) i=9; bestmove=localposition; bestcost=cost; } form[localposition].value=""; } return bestmove; } // complain if user attempts to change board function complain(field) { field.form.output.focus(); // put focus eleswhere alert("Don't change the game fields directly!"); } //a href="http://www.ucsd.edu/ // the end --> </SCRIPT> <FORM> <INPUT SIZE=1 NAME="a0" OnFocus="complain(this)"> <INPUT TYPE="button" NAME="b0" OnClick="clickit(this)"> <INPUT SIZE=1 NAME="a1" OnFocus="complain(this)"> <INPUT TYPE="button" NAME="b1" OnClick="clickit(this)"> <INPUT SIZE=1 NAME="a2" OnFocus="complain(this)"> <INPUT TYPE="button" NAME="b2" OnClick="clickit(this)"> <BR> <INPUT SIZE=1 NAME="a3" OnFocus="complain(this)"> <INPUT TYPE="button" NAME="b3" OnClick="clickit(this)"> <INPUT SIZE=1 NAME="a4" OnFocus="complain(this)"> <INPUT TYPE="button" NAME="b4" OnClick="clickit(this)"> <INPUT SIZE=1 NAME="a5" OnFocus="complain(this)"> <INPUT TYPE="button" NAME="b5" OnClick="clickit(this)"> <BR> <INPUT SIZE=1 NAME="a6" OnFocus="complain(this)"> <INPUT TYPE="button" NAME="b6" OnClick="clickit(this)"> <INPUT SIZE=1 NAME="a7" OnFocus="complain(this)"> <INPUT TYPE="button" NAME="b7" OnClick="clickit(this)"> <INPUT SIZE=1 NAME="a8" OnFocus="complain(this)"> <INPUT TYPE="button" NAME="b8" OnClick="clickit(this)"> <BR> <BR> <BR> Message: <INPUT NAME="output" TYPE="text"><BR> <BR> Difficulty: <SELECT NAME="difficulty" OnChange="diff=form.difficulty[form.difficulty.selectedIndex].value;"> <OPTION VALUE=1> Very Easy <OPTION VALUE=2> Easy <OPTION VALUE=3 SELECTED> Medium <OPTION VALUE=4> Hard (may think a long time) </SELECT> <BR><INPUT TYPE="button" VALUE="Computer Moves First" OnClick=" if (!step++) this.form.a4.value='O';"> <BR><INPUT TYPE="reset" VALUE="Restart" OnClick="clear_all(this.form)"> </FORM></HTML> js前端显示 跪求帮忙, 在Safari中动态创建下拉列表时所出现的问题 怎么判断鼠标点击的是什么? javaScript的一个问题,高手help div与图片透明的问题 请问怎么向一个javascript的函数传递参数???? 这段Javascript应该如何实现 如何让所有链接都在一个弹出窗口中打开 如何屏蔽掉IE右上角的关闭按钮 在线等待,请指教关于window.opener使用出错问题。谢谢。 如何制作下拉导航菜单 怎么判断鼠标按下时,键盘上是否按下了chtr+z?
我看到这个js才牛。<html>
<body>
<SCRIPT LANGUAGE="LiveScript">
<!-- This Script Created by Chris Englmeier: http://www.geocities.com/SiliconValley/Heights/2052/ -->
<!-- For this and 100s of other Free Javascripts, check out: -->
<!-- Free-Javascripts.com @ http://www.free-javascripts.com/ --> <!--
step = 0;
diff=3;
// change board when button is clicked
function clear_all(form) {
step = 0;
for (i=0;i<9; ++i) {
position="a"+i;
form[position].value="";
}
}
// change board when button is clicked
function clickit(field) {
if (step == -1) {alert("Reset to play again"); return;} position=field.name.substring(1,2,1);
position = 'a'+position;
if (field.form[position].value !="") {alert("Can't go there"); return;}
field.form[position].value="X";
if (eval_pos(field.form)) {
field.form.output.value="You Win!";
step = -1;
return;
}
position=get_move(field.form);
field.form.output.value='I moved to ' + position.substring(1,2,1);
if (position=="") {
field.form.output.value="No Winner.";
step = -1; return;
}
field.form[position].value="O";
if (eval_pos(field.form)) {
field.form.output.value="You Lose!";
step = -1;
}
} // see if there is a winner
function eval_pos(form) {
if ((form.a0.value!="" &&
form.a0.value==form.a3.value && form.a0.value==form.a6.value)|| (form.a0.value!=""
&& form.a0.value==form.a1.value && form.a0.value==form.a2.value) ||
(form.a0.value!=""
&& form.a0.value==form.a4.value && form.a0.value==form.a8.value) ||
(form.a1.value!=""
&& form.a1.value==form.a4.value && form.a1.value==form.a7.value) ||
(form.a2.value!=""
&& form.a2.value==form.a5.value && form.a2.value==form.a8.value) ||
(form.a2.value!=""
&& form.a2.value==form.a4.value && form.a2.value==form.a6.value) ||
(form.a3.value!=""
&& form.a3.value==form.a4.value && form.a3.value==form.a5.value) ||
(form.a6.value!=""
&& form.a6.value==form.a7.value && form.a6.value==form.a8.value))
return true;
else
return false;
} function f(a) {
if (a == "") return "."; else return a;
} // get position for move.
function comp_move(form,player,weight,depth) { var cost;
var bestcost=-2;
var position;
var newplayer;
if (player=="X") newplayer="O"; else newplayer="X";
if (depth==diff) return 0; if (eval_pos(form)) return 1;
for (var i=0; i<9; ++i) {
position='a'+i;
if (form[position].value != "")
continue;
form[position].value=player;
cost = comp_move(form,newplayer, -weight, depth+1);
if (cost > bestcost) {
bestcost=cost;
if (cost==1) i=9;
}
form[position].value="";
}
if (bestcost==-2) bestcost=0;
return(-bestcost);
} // get position for move.
function get_move(form) {
var cost;
var bestcost=-2;
bestmove="";
// don't think about first move.
if (step++ == 0)
if (form.a4.value=="")
return "a4";
else
if (form.a0.value=="")
return "a0"; for (var i=0; i<9; ++i) {
localposition='a'+i;
if (form[localposition].value != "")
continue;
form[localposition].value="O";
cost=comp_move(form,"X", -1, 0);
if (cost > bestcost) {
if (cost==1) i=9;
bestmove=localposition;
bestcost=cost;
}
form[localposition].value="";
}
return bestmove;
} // complain if user attempts to change board
function complain(field) {
field.form.output.focus(); // put focus eleswhere
alert("Don't change the game fields directly!");
}
//a href="http://www.ucsd.edu/
// the end -->
</SCRIPT>
<FORM>
<INPUT SIZE=1 NAME="a0" OnFocus="complain(this)">
<INPUT TYPE="button" NAME="b0" OnClick="clickit(this)">
<INPUT SIZE=1 NAME="a1" OnFocus="complain(this)">
<INPUT TYPE="button" NAME="b1" OnClick="clickit(this)">
<INPUT SIZE=1 NAME="a2" OnFocus="complain(this)">
<INPUT TYPE="button" NAME="b2" OnClick="clickit(this)">
<BR> <INPUT SIZE=1 NAME="a3" OnFocus="complain(this)">
<INPUT TYPE="button" NAME="b3" OnClick="clickit(this)">
<INPUT SIZE=1 NAME="a4" OnFocus="complain(this)">
<INPUT TYPE="button" NAME="b4" OnClick="clickit(this)">
<INPUT SIZE=1 NAME="a5" OnFocus="complain(this)">
<INPUT TYPE="button" NAME="b5" OnClick="clickit(this)">
<BR> <INPUT SIZE=1 NAME="a6" OnFocus="complain(this)">
<INPUT TYPE="button" NAME="b6" OnClick="clickit(this)">
<INPUT SIZE=1 NAME="a7" OnFocus="complain(this)">
<INPUT TYPE="button" NAME="b7" OnClick="clickit(this)">
<INPUT SIZE=1 NAME="a8" OnFocus="complain(this)">
<INPUT TYPE="button" NAME="b8" OnClick="clickit(this)">
<BR>
<BR>
<BR>
Message: <INPUT NAME="output" TYPE="text"><BR>
<BR>
Difficulty: <SELECT NAME="difficulty"
OnChange="diff=form.difficulty[form.difficulty.selectedIndex].value;">
<OPTION VALUE=1> Very Easy
<OPTION VALUE=2> Easy
<OPTION VALUE=3 SELECTED> Medium
<OPTION VALUE=4> Hard (may think a long time)
</SELECT>
<BR><INPUT TYPE="button" VALUE="Computer Moves First" OnClick="
if (!step++) this.form.a4.value='O';"> <BR><INPUT TYPE="reset" VALUE="Restart" OnClick="clear_all(this.form)">
</FORM></HTML>