javascriptはよく使う


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>

2.buttomが色づきます
<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>
3.ページは現在の日付を表示します.
<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>
4.jsはlinkを開いて、close
<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>