⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 you6.htm

📁 javascript各种效果的实例及源代码
💻 HTM
字号:
<html>
<head>
<title>一个输赢游戏</title>
<style type="text/css">
<!--
body {  font-family: "宋体"; font-size: 9pt; margin-top: 0px; margin-left: 0px; margin-right: 0px}
A { COLOR: black; FONT-SIZE: 9pt; FONT-WEIGHT: 400; TEXT-DECORATION: none }
 A:hover { COLOR: red; FONT-SIZE: 9pt; FONT-WEIGHT: 400; TEXT-DECORATION: underline }
a:active     { font: 9pt "宋体"; cursor: hand; color: #FF0033 }

-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function playGame(choice) {
with (document.game) {
comp = Math.round((Math.random() * 2) + 1); 
var choicename;
if (comp == 1) choicename = "rock";
if (comp == 2) choicename = "paper";
if (comp == 3) choicename = "scissors";
msg.value = 'The computer chose ' + choicename + ';  ';

switch(choice) { // calculates score
case 1 : // rock
         if (comp == 1) {  draw.value++; msg.value += 'It is a draw.'; break; }
         if (comp == 2) {  loss.value++;  msg.value += 'You lost!';     break; }
         if (comp == 3) {  win.value++; msg.value += 'You won!';      break; }
case 2 : // paper
         if (comp == 1) {  win.value++;  msg.value += 'You won!';      break; }
         if (comp == 2) {  draw.value++; msg.value += 'It is a draw.'; break; }
         if (comp == 3) {  loss.value++; msg.value += 'You lost!';     break; }
case 3 : // scissors
         if (comp == 1) {  loss.value++;  msg.value += 'You lost!';     break; }
         if (comp == 2) {  win.value++; msg.value += 'You won!';      break; }
         if (comp == 3) {  draw.value++; msg.value += 'It is a draw.'; break; }
      }
      msg.value += '  Go again!';
   }
}
//  End -->
</script>
</head>
<body bgcolor="#fef4d9"> 
<br>
<br>
<center><font color=red face="隶书" size=6>一个输赢游戏</font></center>
<br>
<br><center>
<table border=5 bordercolor=blue borderlight=green>
<tr><td align=center><font size=5 color=red face="Arial, Helvetica, sans-serif"><strong>下面为效果显示区!</strong></font></td></tr><tr><td align=center width=400 height=200>
这是一个与电脑玩剪刀、包子、锤的游戏
<form name=game>
<table border=1 cellpadding=5>
<tr>
<td align=center>请选择你用:</td>
<td align=center><a href="javascript:void(0);" onClick="playGame(1);"><img src="rock.gif" width=29 height=23 border=0></a></td>
<td align=center><a href="javascript:void(0);" onClick="playGame(2);"><img src="paper.gif" width=29 height=23 border=0></a></td>
<td align=center><a href="javascript:void(0);" onClick="playGame(3);"><img src="scissors.gif" width=29 height=23 border=0></a></td>
</tr>
<tr>
<td colspan=4 align=center><input type=text name=msg size=45></td>
</tr>
<tr>
<td colspan=4 align=center>
<input type=text name=win readonly value="0" size="2"> 赢  
<input type=text name=loss readonly value="0" size="2"> 输   
<input type=text name=draw readonly value="0" size="2"> 平
</td>
</tr>
</table>
</form></td></tr>
</table></center>
<br>
<br>
<center>
<textarea name=source rows=12 cols=45 class=yk9>
脚本说明:
第一步:把如下代码加入<head>区域中
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function playGame(choice) {
with (document.game) {
comp = Math.round((Math.random() * 2) + 1); 
var choicename;
if (comp == 1) choicename = "rock";
if (comp == 2) choicename = "paper";
if (comp == 3) choicename = "scissors";
msg.value = 'The computer chose ' + choicename + ';  ';

switch(choice) { // calculates score
case 1 : // rock
         if (comp == 1) {  draw.value++; msg.value += 'It is a draw.'; break; }
         if (comp == 2) {  loss.value++;  msg.value += 'You lost!';     break; }
         if (comp == 3) {  win.value++; msg.value += 'You won!';      break; }
case 2 : // paper
         if (comp == 1) {  win.value++;  msg.value += 'You won!';      break; }
         if (comp == 2) {  draw.value++; msg.value += 'It is a draw.'; break; }
         if (comp == 3) {  loss.value++; msg.value += 'You lost!';     break; }
case 3 : // scissors
         if (comp == 1) {  loss.value++;  msg.value += 'You lost!';     break; }
         if (comp == 2) {  win.value++; msg.value += 'You won!';      break; }
         if (comp == 3) {  draw.value++; msg.value += 'It is a draw.'; break; }
      }
      msg.value += '  Go again!';
   }
}
//  End -->
</script>


第二步:把如下代码加入<body>区域中
<form name=game>
<table border=1 cellpadding=5>
<tr>
<td align=center>User:</td>
<td align=center><a href="javascript:void(0);" onClick="playGame(1);"><img src="rock.gif" width=29 height=23 border=0></a></td>
<td align=center><a href="javascript:void(0);" onClick="playGame(2);"><img src="paper.gif" width=29 height=23 border=0></a></td>
<td align=center><a href="javascript:void(0);" onClick="playGame(3);"><img src="scissors.gif" width=29 height=23 border=0></a></td>
</tr>
<tr>
<td colspan=4 align=center><input type=text name=msg size=45></td>
</tr>
<tr>
<td colspan=4 align=center>
<input type=text name=win readonly value="0" size="2"> Wins  
<input type=text name=loss readonly value="0" size="2"> Losses   
<input type=text name=draw readonly value="0" size="2"> Draws
</td>
</tr>
</table>
</form> 
</textarea>
<SCRIPT LANGUAGE="JavaScript">

<!-- hide

function goHist(a) 

{

   history.go(a);

}

//-->

</script>

<FORM METHOD="post">
<INPUT TYPE="button" VALUE="返回" onClick="goHist(-1)" style="background-color: #8000FF; color: rgb(255,255,255)">
</form>
</center>
<br>
<br>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -