边学边用javascript(读书笔记)

来源:互联网 发布:gitlab ci php 编辑:程序博客网 时间:2024/06/03 23:03

P19
认识html

_blank弹出新帧
_self指向本帧
_parent父帧
_top最顶层帧

P61
未定义undefined
 
document.write("hello"+"/n");
document.write("name/'tree/'");
数组
week=new Array{"sunday","monday"};
document.write(week);
<body onload="f()">
 onunload

P131第五章,js内置对象
month=new Array();
delete month[2];

P141
Array对象的属性和方法

P146
String对象的方法
charAt(num)
var name="tree";
name.bold();
name.toUpperCase();
name.fontsize(6);
name.substring(0,4);
使用Date对象
today=new Date();
year=today.getFullYear();
month=today.getMonth()+1;
day=today.getDate();
theweek=today.getDay();
getHours();getMinutes();getSeconds();
Global对象和Number对象


P165
第六章,document对象
P178止

P193window对象和frame对象

P218止表单对象

练习代码一

  1. <html xmlns="http://www.w3.org/1999/xhtml" >
  2. <head>
  3.     <title>无标题页</title>
  4.     <script type="text/javascript">
  5.         function f(){
  6.             //alert("hello");
  7.             name=event.type;
  8.             alert(name);
  9.         }
  10.         //document.form1.btn1.onclick=f;
  11.         function nomenu(){
  12.             alert("不能用快捷菜单");
  13.             event.returnValue=false;
  14.         }
  15.         function before(){
  16.             alert("before");
  17.         }
  18.         function after(){
  19.             alert("after");
  20.         }
  21.         function check(){
  22.             var txt=document.getElementById("i1");
  23.             alert(txt.value());
  24.         }
  25.         function createwindow(){
  26.             window.open("js_test.htm","mywindow","menubar=no,height=200,width=300");
  27.         }
  28.         document.onclick=function(){
  29.             createwindow();
  30.         }
  31.     </script>
  32. </head>
  33. <body oncontextmenu="nomenu();"><!--oncontextmenu属性必须删除第一行-->
  34. <form method="post" name="form1" action="js_test.htm" onsubmit="check();">
  35. <input type="button" name="btn1" value="hello" />
  36. <input id="i1" type="text" onblur="after();" onfocus="before();" />
  37. <input type="submit" value="submit" />
  38. </form>
  39. </body>
  40. </html>

练习代码二

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4.     <title>读书笔记《javascript边学边用》</title>
  5.     <script type="text/javascript">
  6.         function f(){
  7.             var i = "20";
  8.             var j = 11;
  9.             var k = j + i;
  10.             var mNumber(i) + j;
  11.             alert(k+'||'+m);
  12.             week=new Array("sunday","monday");
  13.             document.write(week);
  14.             document.write(week.length);
  15.             //document.write("name/'tree/'");
  16.         }
  17.         function f1(){
  18.             num = prompt("enter:");
  19.             alert(num);
  20.         }
  21.         function f2(){
  22.             var con;
  23.             con=confirm("是/否");
  24.             if(con==true)
  25.                 alert("是");
  26.             else
  27.                 alert("否");
  28.         }
  29.         function f3(msg){
  30.             var answer=prompt(msg,"www.163.com");
  31.             if(answer==null)alert("no");
  32.             else alert("yes"+answer);
  33.         }
  34.         function f4(){
  35.             var i = Math.PI*2;
  36.             alert(i);
  37.         }
  38.         function f5(){
  39.             for(var i in document){
  40.                 document.writeln(i+"<br/>");
  41.             }
  42.         }
  43.         function f6(){
  44.             with(Math){//Math.sin(30)省了.
  45.                 var i = sin(30);
  46.                 alert(i);
  47.             }
  48.         }
  49.         function f7(){
  50.             var data=new Array("1","2");
  51.             Array.prototype.fun=fun;
  52.             data.fun();
  53.         }
  54.         function fun(){
  55.             alert("fun");
  56.         }
  57.         function f8(){
  58.             var c1=new Array("1","2");
  59.             var c2=new Array("3","4");
  60.             var c3=c1.concat(c2);
  61.             alert(c3);
  62.         }
  63.         function f9(){
  64.             var c1=new Array("1","8");
  65.             var c2=new Array("3","4");
  66.             var c3=c1.concat(c2);
  67.             c3.sort();
  68.             alert(c3);
  69.         }
  70.         function f10(){
  71.             var i = eval("1+2");
  72.             alert(i);
  73.         }
  74.         function f11(){
  75.             newnewfun=new Function("x","y","z=x+y;return z");
  76.             var x=Number(22);
  77.             var y=Number(11);
  78.             alert(newfun(11,y));
  79.         }
  80.         document.onclick=function(){
  81.             //alert('');
  82. //            f1();
  83. //            f3("hello");
  84.               f11();
  85.         }
  86.     </script>
  87. </head>
  88. <body>
  89. <div>
  90. <a href="#i1">i1</a>
  91. <ul>
  92.     <li>List Item</li>
  93.     <li>hello</li>
  94.     <li>hello</li>
  95. </ul>
  96. <ol>
  97.     <li>hello</li>
  98.     <li>hello</li>
  99.     <li>hello</li>    
  100. </ol>
  101. <pre>
  102. 原样输出    空格
  103. 回车
  104. </pre>
  105. <a name="i1">i1</a>
  106. </div>
  107. <form id="f1" action="HTMLPage.htm" method="post">
  108. <input name="txt" type="text" />
  109. <input type="submit" />
  110. </form>
  111. </body>
  112. </html>