JavaScript 第二帖
2004-12-29 21:11
267 查看
井字棋
<html>
<head>
</head>
<script language="javascript">
var index=-1;
////////////
function play(buttons)
{
index=-1*index;
if(index==1)
{
buttons.value="#";
getWiner();
return false;
}
buttons.value="&";
}
/////////////
function getWiner()
{
if(form1.B1.value!=""&&form1.B1.value==form1.B2.value&&form1.B1.value==form1.B3.value)//1
{
alert(form1.B1.value+" is the winer!");
}
if(form1.B1.value!=""&&form1.B1.value==form1.B4.value&&form1.B1.value==form1.B7.value)//2
{
alert(form1.B1.value+" is the winer!");
}
if(form1.B1.value!=""&&form1.B1.value==form1.B5.value&&form1.B1.value==form1.B9.value)//3
{
alert(form1.B1.value+" is the winer!");
}
if(form1.B2.value!=""&&form1.B2.value==form1.B5.value&&form1.B2.value==form1.B8.value)//4
{
alert(form1.B2.value+" is the winer!");
}
if(form1.B3.value!=""&&form1.B3.value==form1.B6.value&&form1.B3.value==form1.B9.value)//5
{
alert(form1.B3.value+" is the winer!");
}
if(form1.B3.value!=""&&form1.B3.value==form1.B5.value&&form1.B3.value==form1.B7.value)//6
{
alert(form1.B3.value+" is the winer!");
}
if(form1.B4.value!=""&&form1.B4.value==form1.B5.value&&form1.B4.value==form1.B6.value)//7
{
alert(form1.B4.value+" is the winer!");
}
if(form1.B7.value!=""&&form1.B7.value==form1.B8.value&&form1.B7.value==form1.B9.value)//8
{
alert(form1.B7.value+" is the winer!");
}
return false;
}
</script>
<body>
<form method="POST" name="form1" >
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="20%" height="89">
<tr>
<td width="33%" height="31" align="center">
<p align="center"><input type="button" name="B1" onClick="play(this)"></td>
<td width="33%" height="31" align="center">
<p align="center"><input type="button" name="B2" onClick="play(this)"></td>
<td width="34%" height="31" align="center">
<input type="button" name="B3" onClick="play(this)"></td>
</tr>
<tr>
<td width="33%" height="29" align="center">
<input type="button" name="B4" onClick="play(this)"></td>
<td width="33%" height="29" align="center">
<input type="button" name="B5" onClick="play(this)"></td>
<td width="34%" height="29" align="center">
<input type="button" name="B6" onClick="play(this)"></td>
</tr>
<tr>
<td width="33%" height="29" align="center">
<input type="button" name="B7" onClick="play(this)"></td>
<td width="33%" height="29" align="center">
<input type="button" name="B8" onClick="play(this)"></td>
<td width="34%" height="29" align="center">
<input type="button" name="B9" onClick="play(this)"></td>
</tr>
</table>
</form>
</body>
</html>
<html>
<head>
</head>
<script language="javascript">
var index=-1;
////////////
function play(buttons)
{
index=-1*index;
if(index==1)
{
buttons.value="#";
getWiner();
return false;
}
buttons.value="&";
}
/////////////
function getWiner()
{
if(form1.B1.value!=""&&form1.B1.value==form1.B2.value&&form1.B1.value==form1.B3.value)//1
{
alert(form1.B1.value+" is the winer!");
}
if(form1.B1.value!=""&&form1.B1.value==form1.B4.value&&form1.B1.value==form1.B7.value)//2
{
alert(form1.B1.value+" is the winer!");
}
if(form1.B1.value!=""&&form1.B1.value==form1.B5.value&&form1.B1.value==form1.B9.value)//3
{
alert(form1.B1.value+" is the winer!");
}
if(form1.B2.value!=""&&form1.B2.value==form1.B5.value&&form1.B2.value==form1.B8.value)//4
{
alert(form1.B2.value+" is the winer!");
}
if(form1.B3.value!=""&&form1.B3.value==form1.B6.value&&form1.B3.value==form1.B9.value)//5
{
alert(form1.B3.value+" is the winer!");
}
if(form1.B3.value!=""&&form1.B3.value==form1.B5.value&&form1.B3.value==form1.B7.value)//6
{
alert(form1.B3.value+" is the winer!");
}
if(form1.B4.value!=""&&form1.B4.value==form1.B5.value&&form1.B4.value==form1.B6.value)//7
{
alert(form1.B4.value+" is the winer!");
}
if(form1.B7.value!=""&&form1.B7.value==form1.B8.value&&form1.B7.value==form1.B9.value)//8
{
alert(form1.B7.value+" is the winer!");
}
return false;
}
</script>
<body>
<form method="POST" name="form1" >
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="20%" height="89">
<tr>
<td width="33%" height="31" align="center">
<p align="center"><input type="button" name="B1" onClick="play(this)"></td>
<td width="33%" height="31" align="center">
<p align="center"><input type="button" name="B2" onClick="play(this)"></td>
<td width="34%" height="31" align="center">
<input type="button" name="B3" onClick="play(this)"></td>
</tr>
<tr>
<td width="33%" height="29" align="center">
<input type="button" name="B4" onClick="play(this)"></td>
<td width="33%" height="29" align="center">
<input type="button" name="B5" onClick="play(this)"></td>
<td width="34%" height="29" align="center">
<input type="button" name="B6" onClick="play(this)"></td>
</tr>
<tr>
<td width="33%" height="29" align="center">
<input type="button" name="B7" onClick="play(this)"></td>
<td width="33%" height="29" align="center">
<input type="button" name="B8" onClick="play(this)"></td>
<td width="34%" height="29" align="center">
<input type="button" name="B9" onClick="play(this)"></td>
</tr>
</table>
</form>
</body>
</html>
相关文章推荐
- javascript小技巧[转]
- javascript实现数字转大写金额的函数
- Firefox、Chrome跑JavaScript几乎一样快
- JavaScript 地震特效
- JSObject.call()--Applet与Javascript通讯
- 如何进行高效JavaScript单元测试
- Windows 2003 系统下访问GeoServer提示开启JavaScript的方法
- iPhone and iPad JavaScript dialogs (alert, confirm, prompt) and windows
- JavaScript try/catch/finally 语句
- JavaScript中如何判断一个对象是不是数组
- JavaScript - 条件分支语句 -
- javascript 小数乘法结果错误的处理方法
- javascript右下角弹层及自动隐藏(自己编写)
- HTML中用JavaScript实现tooptip功能
- 用JAVASCRIPT实现静态对象、静态方法和静态属性
- [LeetCode][JavaScript]Merge Two Sorted Lists
- 浅析JavaScript 调试方法和技巧
- javaScript标题栏滚动
- JavaScript中的Try...Catch 语句
- 客户端JavaScript加密数据,服务端Java解密数据