1.计算器js实现
<SCRIPT language="javascript"> function calculator(op) { var num1,num2; num1=parseFloat(document.form.txtNum1.value); //数据类型转换 num2=parseFloat(document.form.txtNum2.value); //数据类型转换 if (op=="+") //判断操作类型 document.form.txtResult.value=num1+num2 ; if (op=="-") document.form.txtResult.value=num1-num2 ; if (op=="*") document.form.txtResult.value=num1*num2 ; if (op=="/" && num2!=0) //num2!=0 被除数不能为0 document.form.txtResult.value=num1/num2 ; } </SCRIPT> </HEAD>
<BODY> <FORM name="form" method="get" action=""> <TABLE width="298" height="132" bgcolor="#66B3FF" border="1" align="center"> <TR> <TD height="35" colspan="3"><H3>计算器</H3></TD> </TR> <TR > <TD width="89" height="24" align="right" >第一个数</TD> <TD width="130"><INPUT name="txtNum1" type="text" class="textBaroder" size="10"></TD> <TD width="65" rowspan="3" align="center" > <INPUT name="addButton2" type="button" value=" + " onClick="calculator('+')"><BR> <INPUT name="subButton2" type="button" value=" - " onClick="calculator('-')"><BR> <INPUT name="mulButton2" type="button" value=" x " onClick="calculator('*')"><BR> <INPUT name="divButton2" type="button" value=" / " onClick="calculator('/')"><BR> </TD> </TR> <TR > <TD height="29" align="right" >第二个数</TD> <TD><INPUT name="txtNum2" type="text" class="textBaroder" size="10"></TD> </TR> <TR> <TD height="32" align="right" >计算结果</TD> <TD><INPUT name="txtResult" type="text" class="textBaroder" size="10"></TD> </TR> </TABLE>
<SCRIPT type="text/javascript" language="javascript"> /* javascript 中带参数的自定义函数调用 */ function change(color){ if(color=="r"){ document.bgColor="red"; }else if(color=="b"){ document.bgColor="blue"; }else if(color=="g"){ document.bgColor="green" } } </SCRIPT> </HEAD> <BODY> <FORM action="" method="get" name="myform"> <TABLE width="459" border="0" cellspacing="0" cellpadding="0" align="center"> <TR align="center"> <TD width="143"> <INPUT type="button" name="btn1" value=" 不许碰我 " onClick="change('b')"></TD> <TD width="153"> <INPUT type="button" name="btn2" value=" 警告你别碰我 " onClick="change('r')"></TD> <TD width="163"> <INPUT name="btn3" type="button" value="给你点颜色看看" onClick="change('g')"></TD> </TR> </TABLE>
<SCRIPT language="JavaScript"> <!-- function disptime( ) { var time = new Date( ); //获得当前时间 var hour = time.getHours( ); //获得小时、分钟、秒 var minute = time.getMinutes( ); var second = time.getSeconds( ); var apm="AM"; //默认显示上午: AM if (hour>12) //按12小时制显示 { hour=hour-12; apm="PM" ; } if (minute < 10) //如果分钟只有1位,补0显示 minute="0"+minute; if (second < 10) //如果秒数只有1位,补0显示 second="0"+second; /*设置文本框的内容为当前时间*/ document.myform.myclock.value =hour+":"+minute+":"+second+" "+apm; /*设置定时器每隔1秒(1000毫秒),调用函数disptime()执行,刷新时钟显示*/ var myTime = setTimeout("disptime()",1000); } //--> </SCRIPT> <STYLE type="text/css"> <!-- /*设置样式:无边框的文本框*/ INPUT { font-size: 30px; border-style:none ; background-color:#FF8B3B; } --> </STYLE> </HEAD> <BODY onLoad="disptime( )"> <FORM NAME="myform"> <TABLE width="100%" border="0" align="center"> <TR> <TD colspan="3"><IMG src="images/mosou.jpg" width="1001" height="457"></TD> </TR> <TR> <TD width="37%"> </TD> <TD width="41%"><H2>当前时间: <INPUT name="myclock" type="text" value="" size="10" > </H2></TD> <TD width="22%"> </TD> </TR> </TABLE>
<SCRIPT language="javascript"> function openwindow( ) { window.status="系统当前状态:您正在注册用户......"; if (window.screen.width == 1024 && window.screen.height == 768) window.showModalDialog("register.html", "注册窗口", "toolbars=0, location=0, statusbars=0, menubars=0,width=700,height=550,scrollbars=1"); else window.alert("请设置分辨率为1024x768,然后再打开"); } function closewindow( ) { if(window.confirm("您确认要退出系统吗?")) window.close( ); } </SCRIPT> <STYLE type="text/css"> <!-- /*设置无下划线的超连接样式*/ A { color: blue; text-decoration: none; } A:hover{ /*鼠标在超链接上悬停时变为颜色*/ color: red; } --> </STYLE> </HEAD> <BODY bgcolor="#CCCCCC"> <TABLE border="0" align="center" bgcolor="#FFFFFF" > <TR> <TD colspan="3"><IMG src="images/head.jpg" width="761" height="389"></TD> </TR> <TR> <TD width="502" > <IMG src="images/foot.jpg" width="502" height="90" align="top"></TD> <TD width="86" valign="top" ><H3><A href="javascript: openwindow( ) ">用户注册 </A></H3></TD> <TD width="263" valign="top" > <H3><A href="javascript: closewindow( ) ">退 出</A></H3></TD> </TR> </TABLE>