js收藏

1. Javascript Notes By shawl.qiu
    linenum
  1. CREATED BY STABX, AT 2006-9-5.
  2. Javascript Notes By shawl.qiu
  3. ---/-------------------------------------------------------------
  4. -3.1 函数比其他代码优先执行
  5. -3. 优先级
  6. -2.4 同时初始化多个变量并赋相同值
  7. -2.3 在函数中使用 var 定义一个变量, 该变量将影响整个函数, 不分先后. 
  8. -2.2 全局变量与局部变量
  9. -2.1.2 普通定义变量 2
  10. -2.1.1 普通定义变量 1
  11. -2.1 普通定义变量
  12. -2. var 定义变量
  13. -1.5 in 操作符
  14. -1.4.2 true 等价 1, false 等价 0.
  15. -1.4 == 与 ===
  16. -1.4.1 NaN
  17. -1.3 0/0=?
  18. -1.2 类型转换
  19. -1.1 -- 与 ++
  20. -1.1.1
  21. -1. 运算符
  22. 0. 语法
  23. 0.1 Switch
  24. 1. 按钮
  25. 1.1 前进后退按钮
  26. 1.2 确认按钮
  27. 1.3 最原始也最实用的  UBB 代码输入方法——SCRIPT & FORM
  28. 1.4 Prompt
  29. 1.5.1 鼠标经过时选中,并隐藏原框的文字, 移开再显示文字 ——文本框
  30. 1.5 鼠标经过时选中 ——复选框 Focus()
  31. 1.6 鼠标经过自动提交表单
  32. 2. 接收键盘事件
  33. 2.1 按任何键关闭窗口 
  34. 2.2 实时显示更改的图片链接
  35. 3. 数组/Array
  36. 3.1 Javascript 结合 Asp 使用数组
  37. 4. 控制图片大小
  38. 5. 双击拷贝文本
  39. 6. IE 全屏显示
  40. 7. 文本框回车链接
  41. 8. 顯示頁面所有元素
  42. 9. 正则表达式
  43. 10. 接收鼠标事件
  44. 10.1 单击鼠标右击关闭窗口 (我用左手)
  45. 10.2 鼠标移过选择表单项
  46. 11. 字符串
  47. 11.1 检测字符串中是否出现某字符
  48. 12. 随机数
  49. 12.1.1 生成 GUID 2
  50. 12.1 生成 GUID
  51. 13. 时间操作
  52. 13.1 以毫秒为单位的倒计时跳转, 来源 CSDN
  53. 14. switch
  54. 14.1 简单 switch
  55. 15 if 判断
  56. 15.1.2 简单 if 判断 3
  57. 15.1.1 简单 if 判断 2
  58. 15.1 简单 if 判断
  59. 15.2 if 判断的 三个 写法
  60. 15.3 判断执行文件使用网络还是使用本地协议
  61. 15.4 if...else 写法
  62. 16. 简单 while
  63. 16. while
  64. 17. do while
  65. 17.1.2 简单 do while
  66. 17.1 简单 do while
  67. 18. for
  68. 18.1 简单 for
  69. 18.2 简单 for 1
  70. 18.3 循环列出从 a - z 的字母
  71. 18.3 n阶乘
  72. 18.4 Fibonacci Numbers
  73. 19. for in
  74. 19.1.1 简单 for in 1
  75. 19.1 简单 for in
  76. 19.2.1 for in 赋值 [数组] 1
  77. 19.2 for in 赋值 [数组]
  78. 20. try, catch, finally
  79. 20.1.1 简单 try, catch 1
  80. 20.1 简单 try, catch
  81. 21. with
  82. 21.1 简单with (另一写法)
  83. 21.1 简单 with
  84. 22. break, continue
  85. 22.1 continue
  86. 22.2.1 break 标签
  87. 22.2 break 
  88. 23. call, apply
  89. 23.1.1 找出数组中最大的数
  90. 23.1 apply
  91. 24. object
  92. 24.1.1 创建简单对象 一
  93. 24.1.2 创建简单对象 二
  94. 24.1 创建简单对象
  95. 24.2.1 创建嵌套对象 1
  96. 24.2 创建嵌套对象
  97. 24.3 删除对象中的属性
  98. 24.4.1 遍历对象中的属性名 1
  99. 24.4 遍历对象中的属性名
  100. 24.5 obj.propertyIsEnumerable('ele')
  101. 24.6 obj.hasOwnProperty('ele')
  102. 25. toString
  103. 25.1 使用 toString 列出数组中的元素
  104. 26. Array()
  105. 26.0.1 简单创建数组, 并赋值 2
  106. 26.0 简单创建数组, 并赋值
  107. 26.0.3 创建数组中的数组
  108. 26.0.4 创建数组中的对象
  109. 26.0.2 简单创建数组
  110. 26.1 [array].push(), [array].pop()
  111. 26.2 数组排序
  112. 26.3 创建数组指定维数, 从 1 开始.
  113. 27. RegExp
  114. 27.1 普通操作 1
  115. 27.2 test 语句
  116. 27.3 exec 语句
  117. 28. new 语法
  118. 29. isNaN
  119. 30. Date()
  120. 30.1 输出年月日, 时分秒 的日期格式
  121. 31. function 函数
  122. 31.1.1.1 三种定义函数的方法 1.1
  123. 31.10 在数组中存储函数, 并引用
  124. 31.1.1 三种定义函数的方法 1
  125. 31.1.2 三种定义函数的方法 2
  126. 31.1 三种定义函数的方法
  127. 31.2 在标签中写函数
  128. 31.3 创建嵌套函数
  129. 31.4.1 创建递归函数 1 
  130. 31.4 创建递归函数
  131. 31.5 创建 函数对象
  132. 31.6 在函数内部定义的函数只能在该函数内部调用
  133. 31.7 定义函数变量, 并赋值
  134. 31.8 变量引用函数
  135. 31.9 在对象中存储函数, 并引用
  136. 31.11 function.call()
  137. 31.12 在函数内定义的变量可以被下级内嵌函数调用 
  138. 32. typeof 查看数据类型
  139. 32.1 
  140. 33. obj.valueOf() 返回原始值
  141. 34. Math 对象
  142. 34.1.1 生成 1 至 4 的随机数
  143. 34.1 Math.random();
  144. 34.2 求 x 的 n 次方
  145. 35. delete 
  146. 36. confirm() 确认框
  147. 36.1 带条件确认框
  148. 37. window.open
  149. 37. window
  150. 37.1 打开没有焦点的窗口
  151. 38. return 返回值
  152. 38.1 return true
  153. 38.2 return undefined
  154. 39. throw
  155. 39.1 简单产生错误
  156. 40. arguments
  157. 40.1 判断 arguments.length
  158. 40.2 列出所有 argument 的值
  159. 40.3 arguments.callee / 调用函数本身
  160. 41. .to******
  161. 41.1 toString
  162. 42. parseInt() / parseFolat()
  163. --------------------------------
  164. 42. parseInt() / parseFolat()
  165. <script type="text/javascript">
  166. //<![CDATA[
  167.     var str='1.1322 this test ';
  168.     document.write(('str like this: ').bold()+str.fontcolor('red')+'<br/>');
  169.     document.write(('parseInt(str): ').bold()+parseInt(str)+'<br/>');
  170.     document.write(('parseFloat(str): ').bold()+parseFloat(str)+'<br/>');
  171.     
  172.     document.write(('parseInt(1111,2): ').bold()+parseInt(1111,2)+'<br/>');
  173.     document.write(('parseInt(1111,8): ').bold()+parseInt(1111,8)+'<br/>');
  174.     document.write(('parseInt(1111): ').bold()+parseInt(1111)+'<br/>');
  175.     document.write(('parseInt(1111,16): ').bold()+parseInt(1111,16)+'<br/>');
  176. //]]>
  177. </script>
  178. 41. .to******
  179. <script type="text/javascript">
  180. //<![CDATA[
  181.     var num=12345.6789
  182.     
  183.     document.write(('parseInt(num): ').bold()+parseInt(num)+'<br/>');
  184.     
  185.     document.write(('num.toFixed(0): ').bold()+num.toFixed(0)+'<br/>');
  186.     document.write(('num.toFixed(2): ').bold()+num.toFixed(2)+'<br/>');
  187.     
  188.     document.write(('num.toExponential(2): ').bold()+num.toExponential(2)+'<br/>');
  189.     document.write(('num.toExponential(1): ').bold()+num.toExponential(1)+'<br/>');
  190.     
  191.     document.write(('num.toPrecision(1): ').bold()+num.toPrecision(1)+'<br/>');
  192.     document.write(('num.toPrecision(2): ').bold()+num.toPrecision(2)+'<br/>');
  193.     
  194. //]]>
  195. </script>
  196. 41.1 toString
  197. <script type="text/javascript">
  198. //<![CDATA[
  199.     var num=123456789
  200.     
  201.     document.write(('num.toString(): ').bold()+num.toString()+'<br/>');
  202.     document.write(('num.toString(2): ').bold()+num.toString(2)+'<br/>');
  203.     document.write(("'0'+num.toString(8): ").bold()+'0'+num.toString(8)+'<br/>');
  204.     document.write(("'0x'+num.toString(16): ").bold()+'0x'+num.toString(16)+'<br/>');
  205. //]]>
  206. </script>
  207. 40. arguments
  208. 40.1 判断 arguments.length
  209. <script type="text/javascript">
  210. //<![CDATA[
  211.     function t(a, b, c, d){
  212.         if(arguments.length!=4)document.write(('error! argument must be 4 element.').fontcolor('red')+' current arguments length: '+arguments.length+'<br/>');
  213.         else document.write(('this right: '+arguments.length).bold()+' arguments<br/>');
  214.     }
  215.     t();
  216.     t('a', 'b', 'c', 'd');
  217.     t('a', 'b', 'c', 'd', 'e');
  218. //]]>
  219. </script>
  220. 40.2 列出所有 argument 的值
  221. <script type="text/javascript">
  222. //<![CDATA[
  223.     function t(){
  224.         for(var i=0; i<arguments.length; i++){
  225.             document.write(('arguments['+i+']').bold()+' = '+arguments[i].fontcolor('red')+'<br/>');
  226.         }
  227.     }
  228.     var temp='test';
  229.     t('aaa', 'bbb', 'ccc', 'ddd', 'eee', temp);
  230. //]]>
  231. </script>
  232. 40.3 arguments.callee / 调用函数本身
  233. <script type="text/javascript">
  234. //<![CDATA[
  235.     var t=function(x){
  236.             document.write(x+'<br/>');
  237.             if(x>1){
  238.                 arguments.callee(x-1);
  239.             }
  240.         }
  241.         t(10);
  242. //]]>
  243. </script>
  244. 39. throw
  245. 39.1 简单产生错误
  246. <script type="text/javascript">
  247. //<![CDATA[
  248.     t(10);
  249.     t();
  250.     
  251.     function t(x){
  252.         if(typeof x==='undefined')throw new Error('x must be own a value');
  253.         document.write(x);
  254.     }
  255. //]]>
  256. </script>
  257. 38. return 返回值
  258. 38.1 return true
  259. <script type="text/javascript">
  260. //<![CDATA[
  261.     function t(ipt){
  262.         window.status=ipt;
  263.         return true;
  264.     }
  265.     t('test this');
  266. //]]>
  267. </script>
  268. 38.2 return undefined
  269. <script type="text/javascript">
  270. //<![CDATA[
  271.     function t(t){
  272.         if(t==null)return;
  273.     }
  274.     document.write(t()); // undefined
  275. //]]>
  276. </script>
  277. 37. window
  278. 37. window.open
  279. 37.1 打开没有焦点的窗口
  280. <script type="text/javascript">
  281. //<![CDATA[
  282.     var w=window.open('/')
  283.     w.blur();
  284.     window.focus();
  285. //]]>
  286. </script>
  287. 36. confirm() 确认框
  288. 36.1 带条件确认框
  289. <script type="text/javascript">
  290. //<![CDATA[
  291.     var x=confirm('what doing with you')
  292.         if(x){alert('ok')}else alert('good choice');
  293. //]]>
  294. </script>
  295. 35. delete 
  296. <script type="text/javascript">
  297. //<![CDATA[
  298.     var t={i:'ok', j:'ok too'}
  299.     document.write(delete t.i); // true
  300.     document.write('<br/>');
  301.     document.write(delete t); // false 不能删除 使用 var 定义的变量或对象
  302.     document.write('<br/>');
  303.     document.write(delete n); // true 删除不存在的元素.
  304.     document.write('<br/>');
  305.     document.write(delete j); // true
  306.     document.write('<br/>');
  307. //]]>
  308. </script>
  309. 34. Math 对象
  310. 34.1 Math.random();
  311. 34.1.1 生成 1 至 4 的随机数
  312. <script type="text/javascript">
  313. //<![CDATA[
  314.     document.write(parseInt(Math.random()*4+1)+'<br/>');
  315. //]]>
  316. </script>
  317. 34.2 求 x 的 n 次方
  318. <script type="text/javascript">
  319. //<![CDATA[
  320.     document.write(Math.pow(2,10));
  321. //]]>
  322. </script>
  323. 33. obj.valueOf() 返回原始值
  324. <script type="text/javascript">
  325. //<![CDATA[
  326.     var a=1, b='test', c=false, d=new Object();
  327.     document.write(a.valueOf()+'<br/>'); // 1
  328.     document.write(b.valueOf()+'<br/>'); // test
  329.     document.write(c.valueOf()+'<br/>'); // false
  330.     document.write(d.valueOf()+'<br/>'); // [object Object]
  331. //]]>
  332. </script>
  333. 32. typeof 查看数据类型
  334. <script type="text/javascript">
  335. //<![CDATA[
  336.     var a=['a', 'b', 'c']
  337.     document.write(typeof a); // object
  338.     document.write(a.valueOf()); // a, b, c
  339.     document.write(typeof null); // object
  340. //]]>
  341. </script>
  342. 32.1 
  343. <script type="text/javascript">
  344. //<![CDATA[
  345.     var a=['a', 'b', 'c']
  346.     document.write(typeof a); // object
  347.     document.write(a.valueOf()); // a, b, c
  348. //]]>
  349. </script>
  350. 31. function 函数
  351. 31.1 三种定义函数的方法
  352. <script type="text/javascript">
  353. //<![CDATA[
  354.     function f(){ alert('function f');};
  355.     var f1=function(){ alert('function f1');};
  356.     var f2=new Function('', "alert('function f2')");
  357.     f(); f1(); f2();
  358. //]]>
  359. </script>
  360. 31.1.1 三种定义函数的方法 1
  361. <script type="text/javascript">
  362. //<![CDATA[
  363.     var t=new Function('a', 'b', 'return a+b;')
  364.     document.write(t('ok ', 'test this'));
  365. //]]>
  366. </script>
  367. 31.1.1.1 三种定义函数的方法 1.1
  368. <script type="text/javascript">
  369. //<![CDATA[
  370.     var t=new Function("return 'test this'")
  371.     document.write(t());
  372. //]]>
  373. </script>
  374. 31.1.2 三种定义函数的方法 2
  375. <script type="text/javascript">
  376. //<![CDATA[
  377.     var t=function(str){return 'this test'+str};
  378.         
  379.         document.write(t(', right.'));
  380. //]]>
  381. </script>
  382. 31.2 在标签中写函数
  383. <div onclick="BLOCKED SCRIPTvar go=function(){alert(111)};go();">div 可用</div>
  384. <div onclick="go()">div1 不可用</div>
  385. <div onclick="BLOCKED SCRIPT( function(){alert(111);} )()">div2 可用</div>
  386. <div onclick="BLOCKED SCRIPTfunction go(){alert(111);}go();">div3 可用</div>
  387. 31.3 创建嵌套函数
  388. <script type="text/javascript">
  389. //<![CDATA[
  390.     function level1(){
  391.         var lNm='level 1'
  392.         document.write(lNm+'<br/>');
  393.         function level2(){
  394.             var lNm='level 2'
  395.             document.write(lNm+'<br/>');
  396.         }
  397.         level2();
  398.     }
  399.     level1();
  400. //]]>
  401. </script>
  402. 31.4 创建递归函数
  403. <%
  404.     var i=0;
  405.     function t(){
  406.         i++;
  407.         if(i<100){
  408.             Response.Write(i+'<br/>');
  409.             return t();
  410.         }
  411.         Response.Write(i+'<br/>');
  412.     }
  413.     t();
  414. %>
  415. 31.4.1 创建递归函数 1 
  416. <script type="text/javascript">
  417. //<![CDATA[
  418.     function fctr(n){
  419.         if(n<=1)return 1;
  420.         return n*fctr(n-1);
  421.     }
  422.     document.write(fctr(4));
  423. //]]>
  424. </script>
  425. 31.5 创建 函数对象
  426. <script type="text/javascript">
  427. //<![CDATA[
  428.     function fT(){
  429.         this.title='o test';
  430.         this.subtitle=fTt();
  431.         function fTt(){
  432.             return 'o subtitle';
  433.         }
  434.     }
  435.     var t=new fT();
  436.         document.write(t.title+'<br/>');
  437.         document.write(t.subtitle+'<br/>');
  438.     t=null;
  439. //]]>
  440. </script>
  441. 31.6 在函数内部定义的函数只能在该函数内部调用
  442. <script type="text/javascript">
  443. //<![CDATA[
  444.     function lev1(){
  445.         document.write('lev 1<br/>');
  446.         function lev2(){
  447.             document.write('lev 2<br/>');
  448.         }    
  449.         lev2();
  450.     }
  451.     lev1();
  452.     lev2(); // 出错, 在函数内部定义的函数只能在该函数内部调用
  453.     
  454. //]]>
  455. </script>
  456. 31.7 定义函数变量, 并赋值
  457. <script type="text/javascript">
  458. //<![CDATA[
  459.     var t=(function(str){return str+str+'<br/>';})('test this ')
  460.     document.write(t);
  461. //]]>
  462. </script>
  463. 31.8 变量引用函数
  464. <script type="text/javascript">
  465. //<![CDATA[
  466.     function t(x){
  467.         x+='';
  468.         return x+x;
  469.     }    
  470.     document.write(t('how fun ')+'<br>'); // how fun how fun 
  471.     var u=t // u 引用 函数 t
  472.     document.write(u('how fun too ')+'<br>'); // how fun too how fun too 
  473. //]]>
  474. </script>
  475. 31.9 在对象中存储函数, 并引用
  476. <script type="text/javascript">
  477. //<![CDATA[
  478.     var o=new Object();
  479.         o.t=function(x){x+=''; return x+x;}
  480.     var t=o.t('test this ');
  481.     document.write(t);
  482. //]]>
  483. </script>
  484. 31.10 在数组中存储函数, 并引用
  485. <script type="text/javascript">
  486. //<![CDATA[
  487.     var a=new Array(3);
  488.         a[0]=function(x){x+='';return x+x};
  489.         a[1]='test this ';
  490.         a[2]=a[0](a[1]);
  491.         document.write(a[2]);
  492. //]]>
  493. </script>
  494. 31.11 function.call()
  495. <script type="text/javascript">
  496. //<![CDATA[
  497.     var o=new Object();
  498.     function f(a, b){
  499.         return a+b
  500.     }
  501.     document.write(f.call(o, 1, 2));
  502. //]]>
  503. </script>
  504. 31.12 在函数内定义的变量可以被下级内嵌函数调用 
  505. <script type="text/javascript">
  506. //<![CDATA[
  507.     function t(){
  508.         var x=" this's test ";
  509.         function u(){
  510.             document.write(x.bold());
  511.         }
  512.         u();
  513.     }
  514.     t();
  515. //]]>
  516. </script>
  517. 30. Date()
  518. 30.1 输出年月日, 时分秒 的日期格式
  519. <script type="text/javascript">
  520. //<![CDATA[
  521.     var $dt=new Date();
  522.     document.write('yyyy-nn-dd: '+$dt.toLocaleDateString()+'<br/>');
  523.     document.write('hh-mm-ss: '+$dt.toLocaleTimeString());
  524. //]]>
  525. </script>
  526. 29. isNaN
  527. <script type="text/javascript">
  528. //<![CDATA[
  529.     var $str='this is string';
  530.     var $num=12.3;
  531.     //alert(isNaN($str));
  532.     alert(isNaN($num));
  533. //]]>
  534. </script>
  535. 28. new 语法
  536.   new Boolean(false)
  537.   new Number(0)
  538.   new String("")
  539.   new Array()
  540.   new Object()
  541.   new Date();
  542.   new Error();
  543. 27. RegExp
  544. 27.1 普通操作 1
  545. <script type="text/javascript">
  546. //<![CDATA[
  547.     var $str='this is a test'
  548.     with(document){
  549.         write('test str is: '+$str+'<br/>');
  550.         write('$str.search(/is a/i): '+$str.search(/is a/i)+'<p/>');
  551.         
  552.         write('$str.replace(/ {1,1}/ig,"--"): '+$str.replace(/ {1,1}/ig,"--")+'<p/>');
  553.         
  554.         write('$str.match(/t[\S]{1,3}/ig): '+$str.match(/t[\S]{1,3}/ig)+'<p/>');
  555.         
  556.         var $temp=$str.match(/(t[\S]{1,3})/ig)
  557.         for ($i=0; $i<$temp.length; $i++){
  558.             write($temp[$i]+'<br/>');
  559.         }
  560.     }
  561. //]]>
  562. </script>
  563. 27.2 test 语句
  564. <script type="text/javascript">
  565. //<![CDATA[
  566.     var $pattern=/this/i;
  567.         alert($pattern.test('this is a test'));
  568. //]]>
  569. </script>
  570. 27.3 exec 语句
  571. <script type="text/javascript">
  572. //<![CDATA[
  573.     var $pattern=/this/ig;
  574.     var $str='this is a test, this is repeat';
  575.     var $result;
  576.     while(($result=$pattern.exec($str))!=null){
  577.         alert($result[0]+'>>> index of str: '+$result.index+' $pattern lastIndex: '+$pattern.lastIndex);
  578.     }
  579. //]]>
  580. </script>
  581. 26. Array()
  582. 26.0 简单创建数组, 并赋值
  583. <script type="text/javascript">
  584. //<![CDATA[
  585.     var ar=new Array();
  586.         for(var i=0; i<10; i++){
  587.             ar[i]='array '+i
  588.             document.write(ar[i]+'<br/>');
  589.         }
  590. //]]>
  591. </script>
  592. 26.0.1 简单创建数组, 并赋值 2
  593. <script type="text/javascript">
  594. //<![CDATA[
  595.     var ar=['v1', 'v2', 'v3', 'v4', 'v5']
  596.     for(var i=0; i<ar.length; i++){
  597.         document.write(ar[i]+'<br/>');
  598.     }
  599. //]]>
  600. </script>
  601. 26.0.2 简单创建数组
  602. <script type="text/javascript">
  603. //<![CDATA[
  604.     var ar=new Array(10);
  605.         document.write(ar.length);
  606. //]]>
  607. </script>
  608. 26.0.3 创建数组中的数组
  609. <script type="text/javascript">
  610. //<![CDATA[
  611.     var ar=new Array('v1', 'v2', 'v3', ['v41', 'v42']);
  612.     for(var i=0; i<ar.length; i++){
  613.         document.write(ar[i].toString()+'<br/>');
  614.     }
  615. //]]>
  616. </script>
  617. 26.0.4 创建数组中的对象
  618. <script type="text/javascript">
  619. //<![CDATA[
  620.     var ar=new Array('v1', 'v2', 'v3', {x:'v41', y:'v42'});
  621.     for(var i=0; i<ar.length; i++){
  622.         if(typeof(ar[i])=='string')
  623.         document.write(ar[i]+'<br/>');
  624.         else if(typeof(ar[i])=='object'){
  625.             document.write('object<br/>');
  626.             for(var j in ar[i]){
  627.                 document.write('obj: '+j+' obj val '+ar[i][j]+'<br/>');
  628.             }
  629.         }
  630.     }
  631. //]]>
  632. </script>
  633. 26.1 [array].push(), [array].pop()
  634. <script type="text/javascript">
  635. //<![CDATA[
  636.     var $array=new Array('a', 'b', 'c', 'd', 'e')
  637.     
  638.     with(document){
  639.         write('source $array.join: '+$array.join()+'<br/>');
  640.         write ($array.length+'<br/>');
  641.         $array.push(1,1,1,1,1,1,1,1,1,1);
  642.         write ('$array.push(1,1,1,1,1,1,1,1,1,1),  $array.length: '+$array.length+'<br/>');
  643.         write('join $array: '+$array.join()+'<p/>');
  644.         
  645.         write ($array.length+'<br/>');
  646.         $array.push(1, 2, 3, 4, 5);
  647.         write ('$array.push(1, 2, 3, 4, 5), $array.length: '+$array.length+'<br/>');
  648.         write('join $array: '+$array.join()+'<p/>');
  649.         
  650.         write('$array.pop(): '+$array.pop()+'<br/>');
  651.         write('$array.length & $array.join(): '+$array.length+' '+$array.join()+'<p/>');
  652.         
  653.         write('$array.pop(10): '+$array.pop(10)+'<br/>');
  654.         write('$array.length & $array.join(): '+$array.length+' '+$array.join()+'<br/>');
  655.     }
  656. //]]>
  657. </script>
  658. 26.2 数组排序
  659. <script type="text/javascript">
  660. //<![CDATA[
  661.     var a=new Array();
  662.     for (var i=0, j=1; i<10;a[i]=j, i++, j++);
  663.     
  664.     document.write('<h2>未排序前:</h2>');
  665.     document.write(a.join());
  666.     
  667.     document.write('<h2>无条件排序:</h2>');
  668.     document.write(a.sort().join());
  669.     
  670.     temp=a.sort(function(a, b){return a-b});
  671.     document.write('<h2>a-b 排序:</h2>');
  672.     document.write(temp.join());
  673.     
  674.     temp=a.sort(function(a, b){return b-a});
  675.     document.write('<h2>b-a 排序:</h2>');
  676.     document.write(temp.join());
  677. //]]>
  678. </script>
  679. 26.3 创建数组指定维数, 从 1 开始.
  680. <script type="text/javascript">
  681. //<![CDATA[
  682.     var a=new Array(3);
  683.     document.write((a.length+'').bold()+'<br/>');
  684.     for(var i=0; i<a.length; i++){
  685.         document.write(i+'<br/>');
  686.     }
  687. //]]>
  688. </script>
  689. 25. toString
  690. 25.1 使用 toString 列出数组中的元素
  691. <script type="text/javascript">
  692. //<![CDATA[
  693.     var $array=new Array('a', 'a1', 'a2');
  694.     alert($array.toString());
  695. //]]>
  696. </script>
  697. 24. object
  698. 24.1 创建简单对象
  699. <script type="text/javascript">
  700. //<![CDATA[
  701.     var $obj=new Object();
  702.     $obj={$title:"object example", $date:Date()}
  703.     alert($obj.$date);
  704. //]]>
  705. </script>
  706. 24.1.1 创建简单对象 一
  707. <script type="text/javascript">
  708. //<![CDATA[
  709.     var cnt=new Object();
  710.         cnt.title='title this';
  711.         cnt.content='content this'
  712.         cnt.date='the publishing date of '+Date();
  713.     
  714.     document.write('title: '+cnt.title+'<br/>cnt.content: '+cnt.content+'<br/>cnt.date: '+cnt.date);
  715. //]]>
  716. </script>
  717. 24.1.2 创建简单对象 二
  718. <script type="text/javascript">
  719. //<![CDATA[
  720.     var cnt={
  721.         title:'title this',
  722.         content:'content this',
  723.         date:'the publishing date of '+Date()
  724.     }
  725.         document.write('title: '+cnt.title+'<br/>cnt.content: '+cnt.content+'<br/>cnt.date: '+cnt.date);
  726. //]]>
  727. </script>
  728. 24.2 创建嵌套对象
  729. <script type="text/javascript">
  730. //<![CDATA[
  731.     var cnt={
  732.         title:{
  733.             headertitle:'header title',
  734.             subtitle:'subtitle this'
  735.         },
  736.         content:'content this',
  737.         date:'the publishing date of '+new Date().toLocaleString()
  738.     }
  739.         document.write('title: '+cnt.title.headertitle.bold().fontcolor('red')+
  740.         '<br/>cnt.title.subtitle: '+cnt.title.subtitle.fontcolor('blue')+
  741.         '<br/>cnt.content: '+cnt.content.fontcolor('goldenrod')+
  742.         '<br/>cnt.date: '+cnt.date);
  743. //]]>
  744. </script>
  745. 24.2.1 创建嵌套对象 1
  746. <script type="text/javascript">
  747. //<![CDATA[
  748.     var o=new Object();
  749.         o.title=' this title ';
  750.         o.content=' this content';
  751.         o.lve=new Object();
  752.         o.lve.title=' this o.lve title';
  753.         o.lve.content=' this o.lve content';
  754.         
  755.         document.write('o.title: '+o.title.bold()+'<br/>');
  756.         document.write('o.content: '+o.content.bold()+'<br/>');
  757.         document.write('o.lve.title: '+o.lve.title.bold()+'<br/>');
  758.         document.write('o.lve.content: '+o.lve.content.bold()+'<br/>');
  759. //]]>
  760. </script>
  761. 24.3 删除对象中的属性
  762. <script type="text/javascript">
  763. //<![CDATA[
  764.     var $obj=new Object();
  765.     $obj={$title:"object example", $date:Date()}
  766.     //alert($obj.$date);
  767.     
  768.     var $name="";
  769.     for(name in $obj)$name+=name+'\n';
  770.     alert($name);
  771.     
  772.     delete $obj.$date
  773.     
  774.     var $name="";
  775.     for(name in $obj)$name+=name+'\n';
  776.     alert($name);
  777. //]]>
  778. </script>
  779. 24.4 遍历对象中的属性名
  780. <script type="text/javascript">
  781. //<![CDATA[
  782.     var $obj=new Object();
  783.     $obj={$title:"object example", $date:Date()}
  784.     //alert($obj.$date);
  785.     
  786.     var $name="";
  787.     for(name in $obj)$name+=name+'\n';
  788.     alert($name);
  789. //]]>
  790. </script>
  791. 24.4.1 遍历对象中的属性名 1
  792. <script type="text/javascript">
  793. //<![CDATA[
  794.     var o=new Object();
  795.         o.title=' this title ';
  796.         o.content=' this content';
  797.         o.lve=new Object();
  798.         o.lve.title=' this o.lve title';
  799.         o.lve.content=' this o.lve content';
  800.         
  801.         for (var i in o){
  802.             if(typeof o[i]!=='object'){
  803.                 document.write('object o, element: '+i.fontcolor('red')+' value: '+o[i].bold()+'<br/>');
  804.             } else {
  805.                 document.write('object '+i+' element<br/>');
  806.                 for(var j in o[i]){
  807.                     document.write('subobject element :'+j.fontcolor('red')+
  808.                     ' subobject value: '+o[i][j].bold()+'<br/>');
  809.                 }
  810.             }
  811.         }
  812. //]]>
  813. </script>
  814. 24.5 obj.propertyIsEnumerable('ele')
  815. <script type="text/javascript">
  816. //<![CDATA[
  817.     var d=new Date();
  818.         d.x='test';
  819.     var s=new String();
  820.     var o=new Object();
  821.     var f=new Function('thest')
  822.     
  823.     document.write(d.propertyIsEnumerable('x'));
  824.     document.write(d.propertyIsEnumerable('y'));
  825. //]]>
  826. </script>
  827. 24.6 obj.hasOwnProperty('ele')
  828. <script type="text/javascript">
  829. //<![CDATA[
  830.     var d=new Date();
  831.         d.x='test';
  832.     var s=new String();
  833.     var o=new Object();
  834.     var f=new Function('thest')
  835.     
  836.     document.write(d.hasOwnProperty('x'));
  837.     document.write(d.hasOwnProperty('y'));
  838. //]]>
  839. </script>
  840. 23. call, apply
  841. 23.1 apply
  842. 23.1.1 找出数组中最大的数
  843. <script type="text/javascript">
  844. //<![CDATA[
  845.     $array=new Array(2, 9, 12, 33, 2, 4444, 22)
  846.     var $temp=Math.max.apply(null, $array)
  847.     alert($temp)
  848. //]]
  849. </script>
  850. 22. break, continue
  851. 22.1 continue
  852. <script type="text/javascript">
  853. //<![CDATA[
  854.     for (var $i=0; $i<10; $i++){
  855.         if($i==5){continue;}
  856.         document.write ($i+'<br/>')
  857.     }
  858. //]]>
  859. </script>
  860. 22.2 break 
  861. 22.2.1 break 标签
  862. <script type="text/javascript">
  863. //<![CDATA[
  864. //document.write('<xmp>');
  865. outerloop:
  866.     for (var i=0; i<10; i++){
  867.         document.writeln(('outerloop:'+i).bold()+'<br/>')
  868.         innerloop:
  869.         for(var j=0; j<10; j++){;
  870.             if(i==5)break outerloop;
  871.             if(j==9)break innerloop;
  872.             document.writeln(('innerloop: '+j).fontcolor('blue')+'<br/>');
  873.         }
  874.     }
  875. //document.write('</xmp>');
  876. //]]>
  877. </script>
  878. 21. with
  879. 21.1 简单 with
  880. <script type="text/javascript">
  881. //<![CDATA[
  882.     with(document){
  883.         write('ok');
  884.     }    
  885. //]]>
  886. </script>
  887. 21.1 简单with (另一写法)
  888.     var $dw=document
  889.     $dw.write('ok this a test');
  890. 20. try, catch, finally
  891. 20.1 简单 try, catch
  892.     try{
  893.         5*kkk
  894.     }
  895.     catch(e){
  896.         alert(e)
  897.     }
  898.     
  899. 20.1.1 简单 try, catch 1
  900. <script type="text/javascript">
  901. //<![CDATA[
  902.     document.write('<h2>window object:</h2>');
  903.     for(var i in window){
  904.         try{
  905.             document.write(i.bold()+' '+(window[i]+'').fontcolor('blue')+'<br/>');
  906.         } catch (e) {
  907.             document.write(i.fontcolor('red').bold()+': ');
  908.             document.write(e.description.fontcolor('red')+'<br/>');
  909.         }
  910.     }
  911. //]]>
  912. </script>
  913. 19. for in
  914. 19.1 简单 for in
  915. <script type="text/javascript">
  916. //<![CDATA[
  917. /*     document.write('<h2>top object:</h2>');
  918.     for(var i in top){
  919.         try{
  920.             document.write(i.bold()+' '+(top[i]+'').fontcolor('blue')+'<br/>');
  921.         } catch (e) {
  922.             document.write(i.fontcolor('red').bold()+': ');
  923.             document.write(e.description.fontcolor('red')+'<br/>');
  924.         }
  925.     }
  926.     
  927.     document.write('<h2>parent object:</h2>');
  928.     for(var i in parent){
  929.         try{
  930.             document.write(i.bold()+' '+(parent[i]+'').fontcolor('blue')+'<br/>');
  931.         } catch (e) {
  932.             document.write(i.fontcolor('red').bold()+': ');
  933.             document.write(e.description.fontcolor('red')+'<br/>');
  934.         }
  935.     }
  936.     
  937.     document.write('<h2>screen object:</h2>');
  938.     for(var i in screen){
  939.         try{
  940.             document.write(i.bold()+' '+(screen[i]+'').fontcolor('blue')+'<br/>');
  941.         } catch (e) {
  942.             document.write(i.fontcolor('red').bold()+': ');
  943.             document.write(e.description.fontcolor('red')+'<br/>');
  944.         }
  945.     }
  946.      */
  947.     try{
  948.         document.write('<h2>clipboardData object:</h2>');
  949.         for(var i in clipboardData){
  950.             try{
  951.                 document.write(i.bold()+' '+(clipboardData[i]+'').fontcolor('blue')+'<br/>');
  952.             } catch (e) {
  953.                 document.write(i.fontcolor('red').bold()+': ');
  954.                 document.write(e.description.fontcolor('red')+'<br/>');
  955.             }
  956.         }
  957.     } catch(ex) {
  958.         document.write((ex+'').fontcolor('red'));
  959.     }
  960.     
  961.     document.write('<h2>window object:</h2>');
  962.     for(var i in window){
  963.         try{
  964.             document.write(i.bold()+' '+(window[i]+'').fontcolor('blue')+'<br/>');
  965.         } catch (e) {
  966.             document.write(i.fontcolor('red').bold()+': ');
  967.             document.write(e.description.fontcolor('red')+'<br/>');
  968.         }
  969.     }
  970. /*     
  971.     document.write('<h2>Option object:</h2>');
  972.     for(var i in Option){
  973.         try{
  974.             document.write(i.bold()+' '+(Option[i]+'').fontcolor('blue')+'<br/>');
  975.         } catch (e) {
  976.             document.write(i.fontcolor('red').bold()+': ');
  977.             document.write(e.description.fontcolor('red')+'<br/>');
  978.         }
  979.     }
  980.  */    
  981.     document.write('<h2>frames object:</h2>');
  982.     for(var i in frames){
  983.         try{
  984.             document.write(i.bold()+' '+(frames[i]+'').fontcolor('blue')+'<br/>');
  985.         } catch (e) {
  986.             document.write(i.fontcolor('red').bold()+': ');
  987.             document.write(e.description.fontcolor('red')+'<br/>');
  988.         }
  989.     }
  990. /*     
  991.     document.write('<h2>self object:</h2>');
  992.     for(var i in self){
  993.         try{
  994.             document.write(i.bold()+' '+(self[i]+'').fontcolor('blue')+'<br/>');
  995.         } catch (e) {
  996.             document.write(i.fontcolor('red').bold()+': ');
  997.             document.write(e.description.fontcolor('red')+'<br/>');
  998.         }
  999.     }
  1000.  */
  1001.     document.write('<h2>document object:</h2>');
  1002.     for(var i in document){
  1003.         document.write(i.bold()+' '+(document[i]+'').fontcolor('blue')+'<br/>');
  1004.     }
  1005.     
  1006.     document.write('<h2>history object:</h2>');
  1007.     for(var i in history){
  1008.         try{
  1009.             document.write(i.bold()+' '+(history[i]+'').fontcolor('blue')+'<br/>');
  1010.         } catch (e) {
  1011.             document.write(i.fontcolor('red').bold()+': ');
  1012.             document.write(e.description.fontcolor('red')+'<br/>');
  1013.         }
  1014.     }
  1015. /*     
  1016.     document.write('<h2>Image object:</h2>');
  1017.     for(var i in Image){
  1018.         try{
  1019.             document.write(i.bold()+' '+(Image[i]+'').fontcolor('blue')+'<br/>');
  1020.         } catch (e) {
  1021.             document.write(i.fontcolor('red').bold()+': ');
  1022.             document.write(e.description.fontcolor('red')+'<br/>');
  1023.         }
  1024.     }
  1025.  */    
  1026.     document.write('<h2>navigator object:</h2>');
  1027.     for(var i in navigator){
  1028.         try{
  1029.             document.write(i.bold()+' '+(navigator[i]+'').fontcolor('blue')+'<br/>');
  1030.         } catch (e) {
  1031.             document.write(i.fontcolor('red').bold()+': ');
  1032.             document.write(e.description.fontcolor('red')+'<br/>');
  1033.         }
  1034.     }
  1035.     
  1036.     document.write('<h2>location object:</h2>');
  1037.     for(var i in location){
  1038.         document.write(i.bold()+' '+(location[i]+'').fontcolor('blue')+'<br/>');
  1039.     }
  1040. //]]>
  1041. </script>
  1042. 19.1.1 简单 for in 1
  1043.     for (var $i in window){
  1044.         document.write($i+'<br/>');
  1045.     }
  1046.     
  1047. 19.2 for in 赋值 [数组]
  1048.     var $array=new Array();
  1049.     var i=0;
  1050.     for ($array[i++] in window){
  1051.         //document.write($i+'<br/>');
  1052.     }
  1053.     alert($array[0]);
  1054.     
  1055. 19.2.1 for in 赋值 [数组] 1
  1056. <script type="text/javascript">
  1057. //<![CDATA[
  1058.     var o={a:'aaa', b:'bbb', c:'ccc'};
  1059.     var a=new Array();
  1060.     var i=0;
  1061.     for(a[i++] in o)document.write(a[i-1]);
  1062.     //for(i in a)document.write(a[i]);
  1063. //]]>
  1064. </script>
  1065. 18. for
  1066. 18.1 简单 for
  1067.     for (var $i=0; $i<10; $i++) {
  1068.         document.write($i)
  1069.     }
  1070. 18.2 简单 for 1
  1071.     for (var $i=0, $j=10; $i<10; $i++, $j--) {
  1072.         document.write(($i*$j)+'<br/>')
  1073.     }
  1074. 18.3 循环列出从 a - z 的字母
  1075. <script type="text/javascript">
  1076. //<![CDATA[
  1077.     for(var $i='a'.charCodeAt(); $i<='z'.charCodeAt(); $i++){
  1078.         document.write(String.fromCharCode($i)+'<br/>')
  1079.     }
  1080. //]]>
  1081. </script>
  1082. 18.3 n阶乘
  1083. <script type="text/javascript">
  1084. //<![CDATA[
  1085.     var $fN=10
  1086.     for (var $i=1, $j=1; $i<=$fN; $i++, $j*=$i){
  1087.         if($i==$fN){document.write($j);}
  1088.     }
  1089. //]]>
  1090. </script>
  1091. 18.4 Fibonacci Numbers
  1092. <script type="text/javascript">
  1093. //<![CDATA[
  1094.     for(var $i=0, $j=1, $k=0, $fbcc=0; $i<50; $i++){
  1095.         document.write($i+'='+$fbcc+'<br/>');
  1096.          $fbcc=$j+$k;
  1097.          $j=$k;
  1098.          $k=$fbcc;
  1099.     }
  1100. //]]>
  1101. </script>
  1102. 17. do while
  1103. 17.1 简单 do while
  1104.     var $count=0
  1105.     do{
  1106.         document.write($count)
  1107.     } while(++$count<10)
  1108.     
  1109. 17.1.2 简单 do while
  1110.     var $count=1
  1111.     do{
  1112.         document.write($count)
  1113.     } while($count++<10)
  1114. 16. while
  1115. 16. 简单 while
  1116.     var $count=0
  1117.     while($count<10){ document.write($count);$count++;}
  1118. 15 if 判断
  1119. 15.1 简单 if 判断
  1120.     function ubbTag(fId, str){
  1121.             document.getElementById(fId).content.focus();
  1122.         var strEnd=str.replace(/\[/ig,'[/')
  1123.         if (strEnd.indexOf('=')>-1){ strEnd=strEnd.replace(/(.*?)\=.*?\]/,'$1]') }
  1124.         if((document.selection)&&(document.selection.type== "Text")){
  1125.             var oStr=document.selection.createRange();
  1126.             oStr.text=str+oStr.text+strEnd
  1127.         } else {
  1128.             document.getElementById(fId).content.value+=str+strEnd
  1129.         }
  1130.     }
  1131. 15.1.1 简单 if 判断 2
  1132. <script type="text/javascript">
  1133. //<![CDATA[
  1134.     var i=0, j=1;
  1135.     i>j?j+=i:i+=j;
  1136.     document.write(i+' '+j);
  1137. //]]>
  1138. </script>
  1139. 15.1.2 简单 if 判断 3
  1140. <script type="text/javascript">
  1141. //<![CDATA[
  1142.     if(!cdti||cdti=='')var cdti='test this';
  1143.     document.write(cdti);
  1144. //]]>
  1145. </script>
  1146.     
  1147. 15.2 if 判断的 三个 写法
  1148. <script type="text/javascript">
  1149. //<![CDATA[
  1150.     var a=b=5, c=6
  1151.     if(a==b)document.write('a equal b <br/>');
  1152.     (a==b)&&document.write('a equal b <br/>');
  1153.     a==b?document.write('a equal b <br/>'):'';
  1154. //]]>
  1155. </script>
  1156. 15.3 判断执行文件使用网络还是使用本地协议
  1157. <script type="text/javascript">
  1158. //<![CDATA[
  1159.     if(location.protocol=='file:'){
  1160.         alert('local')
  1161.     } else alert('internet');
  1162. //]]>
  1163. </script>
  1164. 15.4 if...else 写法
  1165. <script type="text/javascript">
  1166. //<![CDATA[
  1167.     //var i=0
  1168.     var i=1
  1169.     if(i==0)document.write('i=0');
  1170.     else document.write('i!=0');
  1171. //]]>
  1172. </script>
  1173. 14. switch
  1174. 14.1 简单 switch
  1175. /*         switch(strEnd){
  1176.             case '\[\/html]' :strEnd=strEnd.replace(/\\[\/,'HTML 和 JS 代码支持[');break;
  1177.             case '\[\/code]' :strEnd=strEnd.replace(/\\[\/,'代码[');break;
  1178.             case '\[\/quote]' :strEnd=strEnd.replace(/\\[\/,'引用[');break;
  1179.             case '\[\/cite]' :strEnd=strEnd.replace(/\\[\/,'引用[');break;
  1180.             case '\[\/linenum]' :strEnd=strEnd.replace(/\\[\/,'显示行号[');break;
  1181.             case '\[\/b]' :strEnd=strEnd.replace(/\\[\/,'粗体[');break;
  1182.             case '\[\/i]' :strEnd=strEnd.replace(/\\[\/,'叙体[');break;
  1183.             case '\[\/u]' :strEnd=strEnd.replace(/\\[\/,'下划线[');break;
  1184.             case '\[\/flash]' :strEnd=strEnd.replace(/\\[\/,'Flash 动画[');break;
  1185.             case '\[\/sound]' :strEnd=strEnd.replace(/\\[\/,'背景声音[');break;
  1186.             case '\[\/mms]' :strEnd=strEnd.replace(/\\[\/,'WM格式流数据[');break;
  1187.             case '\[\/rtsp]' :strEnd=strEnd.replace(/\\[\/,'Real格式流数据[');break;
  1188.             case '\[\/ra]' :strEnd=strEnd.replace(/\\[\/,'在线Real Player播放音频文件[');break;
  1189.             case '\[\/real]' :strEnd=strEnd.replace(/\\[\/,'Real Player 播放视频文件[');break;
  1190.             case '\[\/wm]' :strEnd=strEnd.replace(/\\[\/,'在线Windows Media Player播放视频文件[');break;
  1191.             case '\[\/wma]' :strEnd=strEnd.replace(/\\[\/,'在线Windows Media Player播放音频文件[');break;
  1192.             case '\[\/iframe]' :strEnd=strEnd.replace(/\\[\/,'插入网页[');break;
  1193.         } */
  1194. 13. 时间操作
  1195. 13.1 以毫秒为单位的倒计时跳转, 来源 CSDN
  1196. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  1197. <script type="text/javascript">
  1198. //<![CDATA[
  1199.     var go=20000;
  1200.     var timer=null;
  1201.     var endTime = new Date().getTime() + go ;
  1202.     function interval()
  1203.     {
  1204.         var n=(endTime-new Date().getTime())/1000;
  1205.         if(n<0) return;
  1206.         document.getElementById("jumpTo").innerHTML = n.toFixed(3);
  1207.         setTimeout(interval, 10);
  1208.     }
  1209.     window.onload=function(){
  1210.         timer=setTimeout("window.location.href='/'", go);
  1211.         interval();
  1212.     }
  1213. //]]>
  1214. </script>
  1215. <span id="jumpTo">20.000</span> 秒后 将自动</span>跳转到
  1216. 12. 随机数
  1217. 12.1 生成 GUID
  1218. <!--start 12.1-->
  1219. <html>
  1220. <!-- DW6 -->
  1221. <head>
  1222. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  1223. <title>Untitled Document</title>
  1224. <script>
  1225. function fGuid()
  1226.     {
  1227.     var g ="";
  1228.     for(var i = 0; i < 32; i++)
  1229.     g += Math.floor(Math.random() * 0xF).toString(0xF) + (i == 8 || i == 12 || i == 16 || i == 20 ? "-" : "");
  1230.     alert(g.toUpperCase());
  1231. }
  1232. </script>
  1233. </head>
  1234. <body onLoad="fGuid();">
  1235. </body>
  1236. </html>
  1237. <!--end 12.1-->
  1238. 12.1.1 生成 GUID 2
  1239. <!--start 12.1.1 -->
  1240. <html>
  1241. <!-- DW6 -->
  1242. <head>
  1243. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  1244. <title>Untitled Document</title>
  1245. <script>
  1246. function fGuid() {
  1247.     var g ="";
  1248.     for(var i = 0; i < 32; i++)
  1249.     g += Math.floor(Math.random() * 0xF).toString(0xF) + (i == 8 || i == 12 || i == 16 || i == 20 ? "-" : "");
  1250.     //alert(g.toUpperCase());
  1251.     return g.toUpperCase();
  1252. }
  1253. </script>
  1254. </head>
  1255. <body>
  1256. <form name="form1" method="post" action="">
  1257.   <input name="textfield" type="text" onMouseMove="this.value=fGuid();" size="50">
  1258. </form>
  1259. </body>
  1260. </html>
  1261. <!--end 12.1.1 -->
  1262. 11.1 检测字符串中是否出现某字符
  1263. <script>
  1264.     function test(str) {
  1265.             if(str.indexOf("|")>0) {
  1266.                 alert("have |")
  1267.             }
  1268.         }
  1269. </script>
  1270. <input type="text" value="kklskldflksd|ksdkfksjd" onMouseOver="test(this.value)" />
  1271. 11. 字符串
  1272. 10.2 鼠标移过选择表单项
  1273. onMouseOver="focus();select();" 
  1274. 10.1 单击鼠标右击关闭窗口 (我用左手)
  1275. <html onmousedown='window.close();'>
  1276. 10. 接收鼠标事件
  1277. 9. 正则表达式
  1278. function rbr() {
  1279.     re=/\<br\/\>*/ig
  1280.     document.all.textarea.value=document.all.textarea.value.replace(re,"")
  1281.     }
  1282. 8. 顯示頁面所有元素
  1283. <script language="JavaScript" type="text/javascript">
  1284. //<![CDATA[
  1285.     for(var i in document) {
  1286.             document.write(i +"="+ document[i]+"<br/>")
  1287.         }
  1288. //]]>
  1289. </script>
  1290. 7. 文本框回车链接
  1291. <script>
  1292. <!-- 
  1293.     function ckKeyPress(jumpto){
  1294.         if(window.event.keyCode==13) {
  1295.             window.location.href="?"+jumpto
  1296.         }
  1297.     } 
  1298. //-->shawl.qiu script
  1299. </script>
  1300.  转到:<input type='text' onmousemove='this.focus();this.select();' onkeypress="ckKeyPress(this.value);" />
  1301. 6. IE 全屏显示
  1302. <script language="JavaScript">
  1303. <!--
  1304.     self.moveTo(0,0)
  1305.     self.resizeTo(screen.availWidth,screen.availHeight)
  1306. //-->
  1307. </script>
  1308. 5. 双击拷贝文本
  1309. <script LANGUAGE="JAVASCRIPT">
  1310. function ClipBoard(tdObj) { //IE Only
  1311.         var holdtext = document.all['holdtext'];
  1312.         holdtext.innerText = tdObj.innerText;
  1313.         Copied = holdtext.createTextRange();
  1314.         Copied.execCommand("Copy");
  1315.         alert("text copied");
  1316.     }
  1317. </script>
  1318. <form NAME="form1" METHOD="post" ACTION="">
  1319.         <textarea id="holdtext" style="display:none" ROWS="10"></textarea>
  1320. </form>
  1321. 4. 控制图片大小
  1322. <img src="images/teach/opera/01.jpg" onload="BLOCKED SCRIPTif(this.width>500)this.width=500;" >
  1323. //如果图片宽度大于 500px, 则 更改宽度为 500px
  1324. 3.1 Javascript 结合 Asp 使用数组
  1325. <%    '连接数据库
  1326.     set rs=server.CreateObject("adodb.recordset") '创建 rs 数据查询
  1327.         rs.open "SELECT  a.*, b.* FROM ctglossarysubcat AS a INNER JOIN ctglossarysupercat AS b ON a.gcid = b.gcid order by a.gcid",MM_conn_string,1
  1328. %>
  1329. <script LANGUAGE="JAVASCRIPT">
  1330.         var onecount; //定义子类计数
  1331.         onecount=0; //设置子类计数默认值为0
  1332.         subcat = new Array(); //定义显示子类数组
  1333. <%        count = 0
  1334.         do while not rs.eof  %>
  1335.             subcat[<%=count%>] = new Array("<%=rs("gscat")%>","<%=rs("a.gcid")%>","<%=rs("gscid")%>"); 
  1336. <%            count = count + 1 
  1337.             rs.movenext
  1338.         loop 
  1339. %>
  1340.             onecount=<%=count%>; //子类条目总数
  1341. </script>
  1342. <%
  1343.         rs.close '关闭 rs 连接
  1344.     set rs=nothing 
  1345. %>
  1346. 3. 数组/Array
  1347. 2.2 实时显示更改的图片链接
  1348.  <input type="text" name="" value="<%response.write siteicon %>" onkeyup="BLOCKED SCRIPTdocument.all.siteicon.src=(this.value);" /> <img src="<%response.write siteicon %>" alt="<%response.write sitename %>" id="siteicon" />
  1349. 2.1 按任何键关闭窗口 
  1350. <body onKeyPress="self.close()">
  1351. 2. 接收键盘事件
  1352. 1.6 鼠标经过自动提交表单
  1353. onMouseOut="submit()"
  1354. 1.5.1 鼠标经过时选中,并隐藏原框的文字, 移开再显示文字 ——文本框
  1355. <input NAME="findtext" TYPE="text" ID="findtext" value="查找" onMouseOver="this.focus();this.value=''" onMouseOut="this.value='查找';this.select()">
  1356. <!-- shawl.qiu script -->
  1357. 1.5 鼠标经过时选中 ——复选框 Focus()
  1358. <input type="checkbox" onMouseOver="checked='true'" />
  1359. <!-- shawl.qiu script -->
  1360. 1.4 Prompt
  1361. function prompter()
  1362.     {
  1363.         
  1364.         urlLink=window.prompt("请输入链接"," http://")
  1365.         text = window.prompt("链接名")
  1366.         
  1367.         if(text!="")
  1368.         document.formT.content.value+=""+text+""
  1369.     }
  1370. 1.3 最原始也最实用的  UBB 代码输入方法——SCRIPT & FORM
  1371. <form name="formT" id="formT" method="post" action="">
  1372.   <input type="button" value="url" onclick="this.form.content.value+=''"/>
  1373.   <input type="button" value="code" onclick="this.form.content.value+='

    CODE:'" />

  1374.   <input type="button" value="quote" onclick="this.form.content.value+='

    QUOTE:

    '"/>
  1375.   <br />
  1376.   <textarea name="content" cols="60" rows="10"></textarea>
  1377.   <br />
  1378.   <input type="submit" name="Submit" value="Submit" />
  1379.   <input type="reset" name="Reset" value="Reset" />
  1380. </form>
  1381. <!-- shawl.qiu script -->
  1382. 1.2 确认按钮
  1383. <script LANGUAGE="JavaScript">
  1384. <!--//确认框, 注意表单名; 按钮属性, 按钮名字不能为 submit
  1385.     function confirmer()
  1386.         {
  1387.             if (confirm("现在提交?")) {
  1388.                 document.formT.submit()
  1389.                 }
  1390.             else {
  1391.                 document.formT.reset()
  1392.                 }
  1393.         }gggg
  1394. //Script By Shawl.qiu
  1395. //-->
  1396. </script>
  1397. <form name="formT" method="post" action="t1.asp">
  1398.     <input type="text" name="textfield" value="确认后提交">
  1399.     <input type="button" name="confbuton" value="提交" onclick="confirmer();">
  1400. </form>
  1401. 1.1 前进后退按钮
  1402. <input TYPE="button" VALUE="后退" ONCLICK="history.back(-1)">
  1403. <input TYPE="button" VALUE="前进" ONCLICK="history.back(+1)">
  1404. 1. 按钮
  1405. 0. 语法
  1406. 0.1 Switch
  1407. function kP() {
  1408.     switch(event.keyCode) {
  1409.         case 27:    //按 ESC 键关闭窗口.
  1410.             window.close()
  1411.             break;    
  1412.         //case 120: //F9 转到主页
  1413.             //window.location.href="/"
  1414.             //break;
  1415.         default:
  1416.         break;
  1417.     }
  1418. }
  1419. -1. 运算符
  1420. -1.1 -- 与 ++
  1421. <script type="text/javascript">
  1422. //<![CDATA[
  1423.     var x;
  1424.     x=0; 
  1425.     document.write('x=0, x++: '+(x++));  // 执行 x 后, x 再加 1
  1426.     x=0; 
  1427.     document.write('<br/>x=0, ++x: '+(++x)); // 执行 x 前, x 先加 1
  1428.     x=2; 
  1429.     document.write('<br/>x=2, x--: '+(x--)); // 执行 x 后, x 再减 1
  1430.     x=2;
  1431.     document.write('<br/>x=2, --x: '+(--x)); // 执行 x 前, x 先减 1
  1432. //]]>
  1433. </script>
  1434. -1.1.1
  1435. <script type="text/javascript">
  1436. //<![CDATA[
  1437.     var i=1;
  1438.         j=++i;
  1439.         document.write(i);  //2
  1440.         document.write('<br/>');
  1441.         document.write(j); //2
  1442.         document.write('<br/>');
  1443.         
  1444.     var k=1
  1445.         l=k++
  1446.         document.write(k);  //2
  1447.         document.write('<br/>');
  1448.         document.write(l); //1
  1449. //]]>
  1450. </script>
  1451. -1.2 类型转换
  1452. <script type="text/javascript">
  1453. //<![CDATA[
  1454.     document.write('100'+100); //'100100' 字符串与数字相加
  1455.     document.write('<br/>');
  1456.     document.write('100'-0); //100 转字符串为数值
  1457.     document.write('<br/>');
  1458.     document.write(100+''); //'100' 数值转字符串
  1459.     document.write('<br/>');
  1460.     document.write(!!100); //true 转布尔值
  1461.     document.write('<br/>');
  1462.     document.write(!100); //false 转布尔值
  1463.     document.write('<br/>');
  1464. //]]>
  1465. </script>
  1466. -1.3 0/0=?
  1467. <script type="text/javascript">
  1468. //<![CDATA[
  1469.     document.write(0/0); //NaN
  1470. //]]>
  1471. </script>
  1472. -1.4 == 与 ===
  1473. -1.4.1 NaN
  1474. <script type="text/javascript">
  1475. //<![CDATA[
  1476.     document.write(NaN==NaN); //false
  1477.     document.write(NaN===NaN); //false
  1478. //]]>
  1479. </script>
  1480. -1.4.2 true 等价 1, false 等价 0.
  1481. <script type="text/javascript">
  1482. //<![CDATA[
  1483.     document.write(1==true); //true
  1484.     document.write('<br/>');
  1485.     document.write(0==false); //true
  1486.     document.write('<br/>');
  1487. //]]>
  1488. </script>
  1489. -1.5 in 操作符
  1490. <script type="text/javascript">
  1491. //<![CDATA[
  1492.     var o={e:'ok', f:'ok'}
  1493.         document.write('e' in o); // true
  1494.         document.write('<br/>');
  1495.         document.write('f' in o); // true
  1496.         document.write('<br/>');
  1497.         document.write('j' in o); // false
  1498.         document.write('<br/>');
  1499.         document.write('toString' in o); // false
  1500.         document.write('<br/>');
  1501. //]]>
  1502. </script>
  1503. -2. var 定义变量
  1504. -2.1 普通定义变量
  1505. <script type="text/javascript">
  1506. //<![CDATA[
  1507.     var i
  1508.         document.write(i+'<br/>');
  1509.     var j=1, k=2
  1510.         document.write(j+k+'<br/>');
  1511.     for(var l=0; l<10; l++)document.write(l+' ');;
  1512. //]]>
  1513. </script>
  1514. -2.1.1 普通定义变量 1
  1515. <script type="text/javascript">
  1516. //<![CDATA[
  1517.     var o={a:'aaa', b:'bbb', c:'ccc'}
  1518.     for(var i in o){
  1519.         document.write('object element name: '+i.bold()+' object value: '+o[i].fontcolor('blue')+'<br/>');
  1520.     }    
  1521. //]]>
  1522. </script>
  1523. -2.1.2 普通定义变量 2
  1524. <script type="text/javascript">
  1525. //<![CDATA[
  1526.     var i=j=k=l='ok';
  1527.     document.write(i.bold()+'<br/>');
  1528.     document.write(j.bold()+'<br/>');
  1529.     document.write(k.bold()+'<br/>');
  1530.     document.write(l.bold()+'<br/>');
  1531. //]]>
  1532. </script>
  1533. -2.2 全局变量与局部变量
  1534. <script type="text/javascript">
  1535. //<![CDATA[
  1536.     var i='global i';//全局
  1537.     function t(){
  1538.         var i='local i'; //局部
  1539.         document.write(i+'<br/>');
  1540.         j='global j' //全局
  1541.         document.write(j+'<br/>');
  1542.     }
  1543.     document.write(i+'<br/>');
  1544.     t();
  1545.     document.write(i+'<br/>');
  1546.     document.write(j+'<br/>');
  1547.     
  1548.     var k='global k'
  1549.     document.write(k+'<br/>');
  1550.     function t1(){
  1551.         k='change global k'
  1552.         document.write(k+'<br/>');
  1553.     }
  1554.     t1();
  1555.     document.write(k+'<br/>');
  1556. //]]>
  1557. </script>
  1558. -2.3 在函数中使用 var 定义一个变量, 该变量将影响整个函数, 不分先后. 
  1559. var scope = "global";
  1560. function f(  ) {
  1561.     alert(scope);         // Displays "undefined", not "global"
  1562.     var scope = "local";  // Variable initialized here, but defined everywhere
  1563.     alert(scope);         // Displays "local"
  1564. }
  1565. f(  ); 
  1566. -2.4 同时初始化多个变量并赋相同值
  1567. <script type="text/javascript">
  1568. //<![CDATA[
  1569.     var i=j=k=l=0;
  1570.     document.write(i+' '+j+' '+k+' '+l+' ');
  1571. //]]>
  1572. </script>
  1573. -3. 优先级
  1574. -3.1 函数比其他代码优先执行
  1575. <script type="text/javascript">
  1576. //<![CDATA[
  1577.     document.write((t(10)+'').bold()+'<br/>'); 
  1578.     t=10;
  1579.     document.write((t+'').bold()+'<br/>'); 
  1580.     function t(n){
  1581.         return n*n;
  1582.     }
  1583. //]]>
  1584. </script>
  1585. ---/---------------------------------------------------------
  1586. 常用参数
  1587. 3. document
  1588. 2. location
  1589. 1. this
  1590. ---------------------------------
  1591. 3.3 写出字符串
  1592. document.write("<input type='button' value='url' onclick='addcontent('','');'/>");
  1593. 3.2 document.from
  1594. 指定 表单域
  1595. 3.1 document.all.id
  1596. 查找指定 HTML 页面 ID 或 名字
  1597. 3. document
  1598. 2.2 转到特定网页
  1599. onClick="location.href=' http://127.0.0.1/'"
  1600. 2.1 单独 location
  1601. 取页面地址
  1602. 2. location
  1603. 1.4 this.height
  1604. 取高度属性
  1605. 1.3 this.width
  1606. 取宽度属性
  1607. 1.2 this.href
  1608. 取链接地址
  1609. 1.1 this.src
  1610. 取图片地址
  1611. 1. this
  1612. ---/---------------------------------------------------------
  1613. 问题集:
  1614. 3. return 返回多个值 2006-10-14 14:13:18
  1615. 2. 理解 setInternal 用法
  1616. 1. 理解 void 用法  
  1617. ---/---------------------------------------------------------
  1618. 相关摘要:
  1619. 24. Keep in mind that the function statement is available in all versions of JavaScript, the Function( ) constructor is available only in JavaScript 1.1 and later, and function literals are available only in JavaScript 1.2 and later. Recall that we said the three functions defined earlier are "more or less" equivalent -- there are some differences between these three techniques for function definition, which we'll consider in Section 11.5.
  1620. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 7.1.3 Function Literals
  1621. 2006-10-19 14:35:56
  1622. 23. The Function( ) constructor expects any number of string arguments. The last argument is the body of the function -- it can contain arbitrary JavaScript statements, separated from each other by semicolons. All other arguments to the constructor are strings that specify the names of the parameters to the function being defined. If you are defining a function that takes no arguments, you simply pass a single string -- the function body -- to the constructor.
  1623. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 7.1.2 The Function( ) Constructor
  1624. 2006-10-19 14:16:18
  1625. 22. Note that ECMAScript v3 does not allow function definitions to appear anywhere; they are still restricted to top-level global code and top-level function code. This means that function definitions may not appear within loops or conditionals, for example.[1] These restrictions on function definitions apply only to function declarations with the function statement. As we'll discuss later in this chapter, function literals (another feature introduced in JavaScript 1.2 and standardized by ECMAScript v3) may appear within any JavaScript expression, which means that they can appear within if and other statements.
  1626. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 7.1 Defining and Invoking Functions
  1627. 2006-10-19 14:10:13
  1628. 21. try and finally can be used together without a catch clause. In this case, the finally block is simply cleanup code that is guaranteed to be executed, regardless of any break, continue, or return statements within the try clause. For example, the following code uses a try/finally statement to ensure that a loop counter variable is incremented at the end of each iteration, even when an iteration terminates abruptly because of a continue statement:
  1629. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 6.17 try/catch/finally
  1630. 2006-10-18 19:18:08
  1631. 20. The continue statement, in both its labeled and unlabeled forms, can be used only within the body of a while, do/while, for, or for/in loop. Using it anywhere else causes a syntax error.
  1632. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 6.12 continue
  1633. 2006-10-18 16:03:46
  1634. 19. The following rules are used to determine whether two values are identical according to the === operator: 
  1635. If the two values have different types, they are not identical. 
  1636. If both values are numbers and have the same value, they are identical, unless either or both values are NaN, in which case they are not identical. The NaN value is never identical to any other value, including itself! To check whether a value is NaN, use the global isNaN( ) function. 
  1637. If both values are strings and contain exactly the same characters in the same positions, they are identical. If the strings differ in length or content, they are not identical. Note that in some cases, the Unicode standard allows more than one way to encode the same string. For efficiency, however, JavaScript string comparison compares strictly on a character-by-character basis, and it assumes that all strings have been converted to a "normalized form" before they are compared. See the "String.localeCompare( )" reference page in the core reference section of this book for another way to compare strings. 
  1638. If both values are the boolean value true or both are the boolean value false, they are identical. 
  1639. If both values refer to the same object, array, or function, they are identical. If they refer to different objects (or arrays or functions) they are not identical, even if both objects have identical properties or both arrays have identical elements. 
  1640. If both values are null or both values are undefined, they are identical. 
  1641. The following rules are used to determine whether two values are equal according to the == operator: 
  1642. If the two values have the same type, test them for identity. If the values are identical, they are equal; if they are not identical, they are not equal. 
  1643. If the two values do not have the same type, they may still be equal. Use the following rules and type conversions to check for equality: 
  1644. If one value is null and the other is undefined, they are equal. 
  1645. If one value is a number and the other is a string, convert the string to a number and try the comparison again, using the converted value. 
  1646. If either value is true, convert it to 1 and try the comparison again. If either value is false, convert it to 0 and try the comparison again. 
  1647. If one value is an object and the other is a number or string, convert the object to a primitive and try the comparison again. An object is converted to a primitive value by either its toString( ) method or its valueOf( ) method. The built-in classes of core JavaScript attempt valueOf( ) conversion before toString( ) conversion, except for the Date class, which performs toString( ) conversion. Objects that are not part of core JavaScript may convert themselves to primitive values in an implementation-defined way. 
  1648. Any other combinations of values are not equal. 
  1649. As an example of testing for equality, consider the comparison: 
  1650. "1" == true 
  1651. This expression evaluates to true, indicating that these very different-looking values are in fact equal. The boolean value true is first converted to the number 1, and the comparison is done again. Next, the string "1" is converted to the number 1. Since both numbers are now the same, the comparison returns true. 
  1652. When the equality operator in JavaScript 1.1 attempted to convert a string to a number and failed, it displayed an error message noting that the string could not be converted, instead of converting the string to NaN and returning false as the result of the comparison. This bug has been fixed in JavaScript 1.2.
  1653. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 5.4 Equality Operators
  1654. 2006-10-16 21:56:30
  1655. 18. In top-level code (i.e., JavaScript code that is not part of a function), you can use the JavaScript keyword this to refer to the global object. Within functions, this has a different use, which is described in Chapter 7.
  1656. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 4.6 Variables as Properties
  1657. 2006-10-16 16:08:34
  1658. 17. Garbage collection is automatic and is invisible to the programmer. You can create all the garbage objects you want, and the system will clean up after you! You need to know only enough about garbage collection to trust that it works; you don't have to wonder about where all the old objects go. For those who aren't satisfied, however, Section 11.3, contains further details on the JavaScript garbage-collection process.
  1659. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 4.5 Garbage Collection
  1660. 2006-10-16 16:01:55
  1661. 16. Primitive Types and Reference Types
  1662. var a = [1,2,3];  // Initialize a variable to refer to an array
  1663. var b = a;        // Copy that reference into a new variable
  1664. a[0] = 99;        // Modify the array using the original reference
  1665. alert(b);         // Display the changed array [99,2,3] using the new reference
  1666. If this result does not seem surprising to you, you're already well familiar with the distinction between primitive and reference types. If it does seem surprising, take a closer look at the second line. Note that it is the reference to the array value, not the array itself, that is being assigned in this statement. After that second line of code, we still have only one array object; we just happen to have two references to it.
  1667. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 4.4 Primitive Types and Reference Types
  1668. 15. 在任何情况下,如果六个月以后您还能毫不费力地阅读和理解所编写的代码,则说明这些代码写得不错。
  1669. //Windows 脚本技术 -- JScript -- 什么是 JScript?
  1670. 2006-10-16 14:12:55
  1671. 14. The rule that all variables declared in a function are defined throughout the function can cause surprising results. The following code illustrates this: 
  1672. var scope = "global";
  1673. function f(  ) {
  1674.     alert(scope);         // Displays "undefined", not "global"
  1675.     var scope = "local";  // Variable initialized here, but defined everywhere
  1676.     alert(scope);         // Displays "local"
  1677. }
  1678. f(  );  
  1679. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 4.3 Variable Scope
  1680. 13. Variable Scope
  1681. The scope of a variable is the region of your program in which it is defined. A global variable has global scope -- it is defined everywhere in your JavaScript code. On the other hand, variables declared within a function are defined only within the body of the function. They are local variables and have local scope. Function parameters also count as local variables and are defined only within the body of the function. 
  1682. Within the body of a function, a local variable takes precedence over a global variable with the same name. If you declare a local variable or function parameter with the same name as a global variable, you effectively hide the global variable. For example, the following code prints the word "local": 
  1683. var scope = "global";         // Declare a global variable
  1684. function checkscope(  ) {
  1685.     var scope = "local";      // Declare a local variable with the same name
  1686.     document.write(scope);    // Use the local variable, not the global one
  1687. }
  1688. checkscope(  );               // Prints "local" 
  1689. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 4.3 Variable Scope
  1690. 2006-10-16 1:11:59
  1691. 12. In general, functions do not know what variables are defined in the global scope or what they are being used for. Thus, if a function uses a global variable instead of a local one, it runs the risk of changing a value upon which some other part of the program relies. Fortunately, avoiding this problem is simple: declare all variables with var
  1692. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 4.3 Variable Scope
  1693. 2006-10-15 22:23:32
  1694. 11. If you attempt to read the value of an undeclared variable, JavaScript will generate an error. If you assign a value to a variable that you have not declared with var, JavaScript will implicitly declare that variable for you. Note, however, that implicitly declared variables are always created as global variables, even if they are used within the body of a function. To prevent the creation of a global variable (or the use of an existing global variable) when you meant to create a local variable for use within a single function, you must always use the var statement within function bodies. It's best to use var for all variables, whether global or local. (The distinction between local and global variables is explored in more detail in the next section.) 
  1695.      
  1696. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 4.2.1 Repeated and Omitted Declarations
  1697. 2006-10-15 22:00:53
  1698. 10. Error Objects
  1699. ECMAScript v3 defines a number of classes that represent errors. The JavaScript interpreter "throws" an object of one of these types when a runtime error occurs. (See the throw and try statements in Chapter 6 for a discussion of throwing and catching errors.) Each error object has a message property that contains an implementation-specific error message. The types of predefined error objects are Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, and URIError. You can find out more about these classes in the core reference section of this book.
  1700. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 3.11 Error Objects
  1701. 2006-10-15 19:39:08
  1702. 9. undefined
  1703. Another special value used occasionally by JavaScript is the undefined value returned when you use either a variable that has been declared but never had a value assigned to it, or an object property that does not exist. Note that this special undefined value is not the same as null. 
  1704. Although null and the undefined value are distinct, the == equality operator considers them to be equal to one another. Consider the following: 
  1705. my.prop == null 
  1706. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 3.8 undefined
  1707. 2006-10-15 18:02:39
  1708. 8. The way to really learn a new programming language is to write programs with it. 
  1709. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 1.10 Exploring JavaScript
  1710. 2006-10-14 2:40:02
  1711. 7. Both Netscape and Microsoft have made their JavaScript interpreters available to companies and programmers who want to embed them in their applications. Netscape's interpreter was released as open source and is now available through the Mozilla organization (see   http://www.mozilla.org/js/). Mozilla actually provides two different versions of the JavaScript 1.5 interpreter. One is written in C and is called "SpiderMonkey." The other is written in Java and, in a flattering reference to this book, is called "Rhino."
  1712. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 1.4 JavaScript in Other Contexts
  1713. 2006-10-14 1:13:44
  1714. 6. 11.1.2 Explicit Type Conversions
  1715. Table 11-1 listed the automatic data type conversions that JavaScript performs. It is also possible to explicitly convert values from one type to another. JavaScript does not define a cast operator as C, C++, and Java do, but it does provide similar facilities for converting data values. 
  1716. As of JavaScript 1.1 (and the ECMA-262 standard), Number( ) , Boolean( ), String( ), and Object( ) may be called as functions as well as being invoked as constructors. When invoked in this way, these functions attempt to convert their arguments to the appropriate type. For example, you could convert any value x to a string with String(x) and convert any value y to an object with Object(y). 
  1717. There are a few other tricks that can be useful for performing explicit conversions. To convert a value to a string, concatenate it with the empty string: 
  1718. var x_as_string = x + ""; 
  1719. To force a value to a number, subtract zero from it: 
  1720. var x_as_number = x - 0; 
  1721. And to force a value to boolean, use the ! operator twice: 
  1722. var x_as_boolean = !!x;
  1723. Because of JavaScript's tendency to automatically convert data to whatever type is required, explicit conversions are usually unnecessary. They are occasionally helpful, however, and can also be used to make your code clearer and more precise.
  1724. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 11.1 Data Type Conversion
  1725. 2006-10-12 12:36:23
  1726. 5. Each RegExp object has five properties. The source property is a read-only string that contains the text of the regular expression. The global property is a read-only boolean value that specifies whether the regular expression has the g flag. The ignoreCase property is a read-only boolean value that specifies whether the regular expression has the i flag. The multiline property is a read-only boolean value that specifies whether the regular expression has the m flag. The final property is lastIndex, a read-write integer. For patterns with the g flag, this property stores the position in the string at which the next search is to begin. It is used by the exec( ) and test( ) methods, as described in the previous section.
  1727. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 10.3.2 RegExp Instance Properties
  1728. 2006-10-9 21:23:26
  1729. 4. the RegExp constructor. search( ) does not support global searches -- it ignores the g flag of its regular expression argument.
  1730. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 10.2 String Methods for Pattern Matching
  1731. 2006-10-9 19:56:40
  1732. 3. We've seen the . operator used to access the properties of an object. It is also possible to use the [] operator, which is more commonly used with arrays, to access these properties. Thus, the following two JavaScript expressions have the same value: 
  1733. object.property
  1734. object["property"] 
  1735. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 8.6 Objects as Associative Arrays 
  1736. 2006-10-9 14:45:13
  1737. 2. The typeof Operator
  1738. typeof is a unary operator that is placed before its single operand, which can be of any type. Its value is a string indicating the data type of the operand. 
  1739. The typeof operator evaluates to "number", "string", or "boolean" if its operand is a number, string, or boolean value. It evaluates to "object" for objects, arrays, and (surprisingly) null. It evaluates to "function" for function operands and to "undefined" if the operand is undefined.
  1740. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 5.10.2 The typeof Operator 
  1741. 1. JavaScript strings (and JavaScript arrays, as we'll see later) are indexed starting with zero.
  1742. ---/---------------------------------------------------------
  1743. 小小心得
  1744. 1. 花括弧定义 对象 元素, 方括弧定义 数组 元素. 2006-10-15 17:55:50

2. Javascript 正则表达式摘要
    linenum
  1. Javascript 与正则表达式 By shawl.qiu 
  2. 语法方法:
  3. 5. str.split()
  4. <script type="text/javascript">
  5. //<![CDATA[
  6.     var str=' this  , is, a, text';
  7.     document.write(str.split(/\s*,\s*/));
  8.     document.write('<br/>');
  9.     document.write(str.split(/\s*,\s*/).join());
  10. //]]>
  11. </script>
  12. 4. str.match()
  13. <script type="text/javascript">
  14. //<![CDATA[
  15.     var str=' This is a test. ';
  16.         document.write(str.match(/\w+/).join());
  17.         document.write('<br/>');
  18.         document.write(str.match(/\w+/g).join());
  19. //]]>
  20. </script>
  21. 3. str.replace()
  22. <script type="text/javascript">
  23. //<![CDATA[
  24.     var str=' This is a test. ';
  25.         document.write(str.replace(/^(\s+)|(\s+)$/,'----------'));
  26.         document.write('<br/>');
  27.         document.write(str.replace(/^(\s+)|(\s+)$/g,'----------'));
  28. //]]>
  29. </script>
  30. 2. str.search()
  31. <script type="text/javascript">
  32. //<![CDATA[
  33.     var str=' This is a test. ';
  34.         document.write(str.search(/this/i));
  35. //]]>
  36. </script>
  37. 1. 子匹配
  38. <script type="text/javascript">
  39. //<![CDATA[
  40.     var str=' this is a test '
  41.     document.write(str.match(/(is+).*?\1/)[0]);
  42. //]]>
  43. </script>
  44. 0. 创建正则表达式模式
  45. 0.1 new RegExp()
  46. <script type="text/javascript">
  47. //<![CDATA[
  48.     var str=' this is a test '
  49.     var re=new  RegExp('\\w+','g');
  50.     document.write(str.match(re));
  51. //]]>
  52. </script>
  53. -1. re.exec(str)
  54. <script type="text/javascript">
  55. //<![CDATA[
  56.     var str=' this is a test '
  57.     var pt=/this|test/g;
  58.     
  59.     var report
  60.     while((report=pt.exec(str))!=null){
  61.         document.write(('match: ').bold()+report[0].fontcolor('red')+'<br/>');
  62.         document.write(('match index: ').bold()+(report.index+'').fontcolor('red')+'<br/>');
  63.         document.write(('match lastIndex: ').bold()+(pt.lastIndex+'').fontcolor('red')+'<p/>');
  64.     }
  65. //]]>
  66. </script>
  67. -2. re.test(str)
  68. <script type="text/javascript">
  69. //<![CDATA[
  70.     var str=' this is a test ';
  71.     var re=/\d+/;
  72.     document.write(re.test(str));
  73.     
  74.     var re=/\w+/;
  75.     document.write(re.test(str));
  76. //]]>
  77. </script>
  78.   
  79. ---/----------------------------------------
  80. 摘要:
  81. 4. The String methods search( ) , replace( ), and match( ) do not use the lastIndex property as exec( ) and test( ) do. In fact, the String methods simply reset lastIndex( ) to 0. If you use exec( ) or test( ) on a pattern that has the g flag set and you are searching multiple strings, you must either find all the matches in each string, so that lastIndex is automatically reset to zero (this happens when the last search fails), or you must explicitly set the lastIndex property to 0 yourself. If you forget to do this, you may start searching a new string at some arbitrary position within the string rather than from the beginning. Finally, remember that this special lastIndex behavior occurs only for regular expressions with the g flag. exec( ) and test( ) ignore the lastIndex property of RegExp objects that do not have the g flag.
  82. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 10.3.1 RegExp Methods for Pattern Matching
  83. 2006-10-20 18:10:36
  84. 3. match method
  85. The match( ) method is the most general of the String regular expression methods. It takes a regular expression as its only argument (or converts its argument to a regular expression by passing it to the RegExp( ) constructor) and returns an array that contains the results of the match. If the regular expression has the g flag set, the method returns an array of all matches that appear in the string. For example: 
  86. "1 plus 2 equals 3".match(/\d+/g)  // returns ["1", "2", "3"] 
  87. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 10.2 String Methods for Pattern Matching
  88. 2006-10-20 17:23:08
  89. 2. search method
  90. Strings support four methods that make use of regular expressions. The simplest is search( ). This method takes a regular expression argument and returns either the character position of the start of the first matching substring, or -1 if there is no match. For example, the following call returns 4: 
  91. "JavaScript".search(/script/i); 
  92. If the argument to search( ) is not a regular expression, it is first converted to one by passing it to the RegExp constructor. search( ) does not support global searches -- it ignores the g flag of its regular expression argument.
  93. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 10.2 String Methods for Pattern Matching
  94. 1. A number of punctuation characters have special meanings in regular expressions. They are: 
  95. ^ $ . * + ? = ! : | \ / ( ) [ ] { }  
  96. //BLOCKED SCRIPT The Definitive Guide, 4th Edition -- 10.1 Defining Regular Expressions
  97. 2006-10-9 19:39:54

posted on 2006-11-26 21:57  KUDO  阅读(587)  评论(0编辑  收藏  举报

导航