日期:2014-05-16  浏览次数:20512 次

javascript初级的一些小代码



function myFunc(){
	document.write("hello word")
	document.write("<h1>This is a header</h1>")
	document.write("<p>This is a paragraph</p>");
	document.write("<p>This is another paragraph</p>");
   
	var x = 2;
    var y = 3;
    var z = x+y;
    document.write(z)
	
    document.write("<p>")
    z==5? document.write("z==5"):document.write("z!=5")
    document.write("</p>")
    
    
    document.write("<p>")
    var d=new Date()
    var time=d.getHours()
    if (time<10) 
    {
    document.write("<b>Good morning</b>")
    }	else{
    	
    	document.write("<b>Good afternoon</b>")
    }	
    document.write("</p>")
    
    
    var d = new Date();
    theDay = d.getDay();
    switch(theDay){
    case 3:
    	document.write("W星期三")
    	break;
    case 4:
    	document.write("thursday")
    	break;
    default:
    	doucument.write("you Gusses!")
    }
   
 /**   
  * 弹出框
    document.write("<p>")
    if(confirm("这是确定提示么")){
    	alert("sure")
    }else{
    	alert("not")
    }
    document.write("</p>")
    
   alert( prompt("输入值","默认为1"));
    */
    document.write("</p>")
    
    
    var x;
    var mycars = new Array();
    mycars[0]="Saab1"
    mycars[1]="Saab2"
    mycars[2]="Saab3"
    	
    for(x in mycars){
	  document.write(x)
	  document.write(mycars[x]+"<br/>") 
    } 	
    
    
    
    var a2 = new Array();
    for(i=0;i<4;i++){
    	a2[i]= new Array(4);
    	for(j=0;j<4;j++){
    		a2[i][j]="["+i+","+j+"]";
    		document.write(a2[i][j]+"</br>")
    	}
    }
    
    
    document.write("</p>")
    document.write(Math.round(4.7))
    document.write("</p>")
    document.write(Math.random())
    document.write("</p>")
    document.write(Math.floor(Math.random()*11)) 
    document.write("</p>")  
   
   
   
   
   
   }