首页 > 代码库 > Javascript设置广告和时间表和数组的学习

Javascript设置广告和时间表和数组的学习

 1 <html> 2 <head> 3 <meta charset="utf-8">    4 <title></title>     5 </head> 6 <body> 7 <hr> 8     <h1>2:使用window.open() 是一个广告?</h1> 9     <input type="submit" onclick="" value="http://www.mamicode.com/关闭"/>10     <script language="javascript">11         for(var i=0;i<5;i++){12             var w=window.open("http://www.baidu.com","baidu"+1,"height=450,width=450");13         }14         function click(){15             w.close();16         }17     </script>18     <hr>19     <h1>3. 编写登录页面:登录按钮、注册按钮(window.location )跳转注册页面?</h1>20     <input type="submit" value="http://www.mamicode.com/注册" onclick="javascript:21         window.location.href=http://www.mamicode.com/‘4.html‘">    22     <input type="submit" value="http://www.mamicode.com/登录" onclick="javascript:23         window.location.href=http://www.mamicode.com/‘3.html‘"/>24     25 </body>26 </html>        

技术分享

 

 

 1 <html> 2 <head> 3 <meta charset="utf-8">    4 <title></title>     5 </head> 6 <body> 7     <h1>4. 获取当前时间,格式如下:2016年9月20日 12:12:12 星期二 </h1> 8     <hr/> 9     <script language="javascript">10         var date=new Date();11         document.write("当前的时间:"+date+"<br/>");12         document.write(date.getFullYear()+"年");13         document.write((date.getMonth()+1)+"月");14         document.write(date.getDate()+"日&nbsp;&nbsp;&nbsp;&nbsp;");15         document.write(date.getHours()+":");16         document.write(date.getMinutes()+":");17         document.write(date.getSeconds());18         document.write("&nbsp;&nbsp;&nbsp;&nbsp;星期"+date.getDay());19     </script>20 </body>21 </html>        

技术分享

 

  1 <html>  2 <head>  3 <meta http-equiv="content-type" content="text/html;charset=utf-8">  4 <title></title>      5 </head>  6 <body>  7     <h1>1:Javascript中数组的学习和练习</h1>  8     <script language="javascript">  9         document.write("1:创建一个空数组"+"<br/>"); 10         var arr1=new Array(); 11         document.write("var arr1 = new Array()"+"<br/>"); 12         document.write("2:指定数组的长度"+"<br/>"); 13         var arr2=new Array(5); 14         document.write("var arr2 = new Array(5)"+"<br/>"); 15         document.write("3:创建数组并初始化参数"+"<br/>"); 16         //console.log(arr2.length); 17         var arr3=new Array(9528,"小别","男"); 18         document.write("var arr3=new Array(9528,小别,男)"+"<br/>"); 19         document.write("4:创建一个数组"+"<br/>"); 20         var arr4=[]; 21         document.write("var arr4 = []"+"<br/>"); 22         document.write("5:使用括号[],并且传入初始值"+"<br/>"); 23         var arr5=[12,23,45,6,8]; 24         document.write("var arr4=[12,23,45,56,6,8]"+"<br/>"); 25         document.write("<hr>"); 26         var arr6=new Array(5); 27         document.write("arr6数组的长度:"+arr6.length+"<br/>"); 28         document.write("arr6数组的元素:"+arr6+"<br/>"); 29         console.log(arr6); 30         var arr7=new Array(5,6); 31         document.write("arr7数组的长度:"+arr7.length+"<br/>"); 32         document.write("arr7数组的元素"+arr7+"<br/>"); 33         var arr8=[11,47,88,525,66,9,4]; 34         document.write("arr8数组的长度:"+arr8.length+"<br/>"); 35         document.write("arr8数组的元素"+arr8+"<br/>"); 36         var arr9=[78,84,51,263,95,62]; 37         document.write("arr9的数组元素:"+arr9+"<br/>"); 38         document.write("arr9[0]="+arr9[0]+"<br/>"); 39         var i=1; 40         document.write("arr9[1]="+arr9[i]+"<br/>"); 41         document.write("arr9[2]="+arr9[++i]+"<br/>"); 42         var array=[74,54,69]; 43         array[5]=12; 44         for(var i=0;i<array.length;i++){ 45             document.write("array"+"["+i+"]"+"="+array[i]+","); 46         } 47         document.write("<hr>"); 48         document.write("数组元素的添加"+"<br/>"); 49         var arr=new Array; 50         arr[0]="编号"; 51         arr[1]="姓名"; 52         arr[2]="年龄"; 53         arr[3]="性别"; 54         document.write("数组元素添加:"+arr+"<br/>"); 55         document.write("数组元素的删除:"+"<br/>"); 56         delete arr[3]; 57         document.write("删除后的效果:"+arr+"<br/>"); 58         document.write("<hr>"); 59         document.write("数组的截取"+"<br/>"); 60         var arr=new Array(45,78,9,6,3,2,5,7); 61         document.write("数组的原始长度:"+arr+"<br/>"); 62         document.write("数组的截取前闭后开:"+arr.slice(1,2)+"<br/>"); 63         document.write("<hr>"); 64         document.write("数组的合并"+"<br/>"); 65         var arr1=[4,7,8,5,2,63]; 66         var arr2=[7,5,2,6,9]; 67         var arr3=arr1.concat(arr2); 68         document.write("合并后的arr3:"+arr3+"<br/>"); 69         document.write("<hr>"); 70         document.write("数组元素的反转"+"<br/>"); 71         var arr1=[12,45,78,9,6,3,6,4,45]; 72         document.write("数组元素反转前:"+arr1+"<br/>"); 73         arr1.reverse(); 74         document.write("数组元素反转后:"+arr1+"<br/>"); 75         document.write("<hr>"); 76         document.write("数组的任意多数的排序"+"<br/>"); 77         var arr=[45,7,555,336,4,2,1,40]; 78         function sortArray(a,b){ 79             return a-b; 80         } 81         document.write("排序前:"+arr+"<br/>"); 82         document.write("排序后:"+arr.sort(sortArray)+"<br/>"); 83         document.write("<hr>"); 84         document.write("数组字符串的学习"+"<br>"); 85         var arr=[11,44,55,66,99,88,77,22,33]; 86         document.write("数组字符串前:"+arr+"<br/>"); 87         document.write("数组字符串化:"+arr.join(" ")+"<br/>"); 88         document.write("数组字符串化:"+arr.join("|")+"<br/>"); 89     </script> 90     <h1>2:浏览器对象模型的学习和练习</h1> 91     <script language="javascript"> 92         window.document.write("所有js全局变量,函数,变量均自动成为window对象的成员"); 93         //window.alert("你好哟!!!"); 94         document.write("<hr>");  95         document.write("window的尺寸"+"<br/>"); 96         var h=window.innerHeight; 97         var w=window.innerWidth; 98         document.write("浏览器现在的高:"+h+"  宽:"+w+"<br/>"); 99         //var ieh=window.document.documentElement.clientHeight;100         //var iew=window.document.documentElement.clientWidth;101         //alert(ieh+""+iew);102         //window.open("http://www.baidu.com","baidu","height=300,width=250");103         document.write("<hr>");104         document.write("可用的屏幕"+"<br/>");105         document.write("可用的屏幕的高度:"+screen.availHeight+"<br/>");106         document.write("可用的屏幕的宽度:"+screen.availWidth+"<br/>");107         document.write("<hr>");108         document.write("Window.location对象用于获取当前页面的地址"+"<br/>");109         document.write("当前页面的路径:"+window.location.pathname+"<br/>");110         //document.write("当前页面的port:"+window.location.port+"<br/>");111     </script>112     <hr>113     <script language="javascript">114         var name=prompt("请输入您的尊姓大名.");115         document.write(name+"<br/>");116     </script>117     <input type="button" value="http://www.mamicode.com/删除" onclick="del()"/>118         <script language="javascript">119             function del(){    120                 if(confirm("您确认删除嘛??")){121                     alert("你好狠心!555555");122                 }else{123                     alert("你真好!美美哒");124                 }125             }126         </script>127 </body>128 </html>

 

Javascript设置广告和时间表和数组的学习