bestxiaok 发表于 2013-2-7 21:22:51

Js学习代码

利用Js对输入的姓名排序
sort.js
var numnames = 0;var names =new Array();function SortNames(){// get the name from the text fieldthename = document.theform.newname.value;//add the name to the arraynames = thename;//Increment the counternumnames++;// sort the arraynames.sort();document.theform.sorted.value=names.join("\n");} sort.htm
<HTML> <HEAD><TITLE> Array Sorting </TITLE><script type="text/javascript" language= "javascript" src="sort.js"></script>   </HEAD> <BODY> <p> Enter two or more name in thetextarea below.</p> <form name="theform"> Name: <input type="text" name = "newname" size="20"> <input type ="button" name="addname" value="Add" ><br> <h2>Sorted names</h2> <textarea cols="60" rows="10" name ="sorted"> the sorted names will appear here! </textarea> <form> </BODY></HTML> 
利用Js显示时间
timegreet.js
 
//get the current datenow = new Date();//split into hours minutes secondshours = now.getHours();mins = now .getMinutes();secs = now.getSeconds();//Display the timedocument.write("<h2>");document.write("hours: "+hours+"mins: "+mins+"secs: "+secs);document.write("</h2>");// display a greeting document.write("<p>");if(hours<10) document.write("Good morning!");else if(hours>=14&&hours<=17) document.write("Good afternoon!");else if(hours>17) document.write("Good evening!");else document.write("Good day!");document.write("</p>"); 
date.htm
<HTML> <HEAD><TITLE> Control Test </TITLE></HEAD> <BODY><h1>Current Date and Time</h1><p><script language="javascript" type="text/javascript" src="timegreet.js"></script></p> </BODY></HTML> 
 
页: [1]
查看完整版本: Js学习代码