赞美女士的词语:js小技巧

来源:百度文库 编辑:中财网 时间:2024/04/30 02:57:31
javascript小技巧-js小技巧收集(转)

每一项都是js中的小技巧,但十分的实用!
1.document.write(""); 输出语句
2.JS中的注释为//
3.传统的HTML文档顺序是:document->html->(head,body)
4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document)
5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或value)
6.一个小写转大写的JS: document.getElementById("output").value = document.getElementById("i
nput").value.toUpperCase();
7.JS中的值类型:String,Number,Boolean,Null,Object,Function
8.JS中的字符型转换成数值型:parseInt(),parseFloat()
9.JS中的数字转换成字符型:(""+变量)
10.JS中的取字符串长度是:(length)
11.JS中的字符与字符相连接使用+号.
12.JS中的比较操作符有:==等于,!=不等于,>,>=,<.<=
13.JS中声明变量使用:var来进行声明
14.JS中的判断语句结构:if(condition){}else{}
15.JS中的循环结构:for([initial e­xpression];[condition];[upadte e­xpression]) {inside loop}
16.循环中止的命令是:break
17.JS中的函数定义:function functionName([parameter],...)
18.当文件中出现多个form表单时.可以用document.forms[0],document.forms[1]来代替.
19.窗口:打开窗口window.open(), 关闭一个窗口:window.close(), 窗口本身:self
20.状态栏的设置:window.status="字符";
21.弹出提示信息:window.alert("字符");
22.弹出确认框:window.confirm();
23.弹出输入提示框:window.prompt();
24.指定当前显示链接的位置:window.location.href="URL"
25.取出窗体中的所有表单的数量:document.forms.length
26.关闭文档的输出流:document.close();
27.字符串追加连接符:+=
28.创建一个文档元素:document.createElement(),document.createTextNode()
29.得到元素的方法:document.getElementById()
30.设置表单中所有文本型的成员的值为空:
var form = window.document.forms[0]
for (var i = 0; i if (form.elements.type == "text"){
form.elements.value = "";
}
}
31.复选按钮在JS中判断是否选中:document.forms[0].checkThis.checked (checked属性代表为是否选中
返回TRUE或FALSE)
32.单选按钮组(单选按钮的名称必须相同):取单选按钮组的长度document.forms[0].groupName.length
33.单选按钮组判断是否被选中也是用checked.
34.下拉列表框的值:document.forms[0].selectName.options[n].value (n有时用下拉列表框名称加上.sel
ectedIndex来确定被选中的值)
35.字符串的定义:var myString = new String("This is lightsword");
36.字符串转成大写:string.toUpperCase(); 字符串转成小写:string.toLowerCase();
37.返回字符串2在字符串1中出现的位置:String1.indexOf("String2")!=-1则说明没找到.
38.取字符串中指定位置的一个字符:StringA.charAt(9);
39.取出字符串中指定起点和终点的子字符串:stringA.substring(2,6);
40.数学函数:Math.PI(返回圆周率),Math.SQRT2(返回开方),Math.max(value1,value2)返回两个数中的最
在值,Math.pow(value1,10)返回value1的十次方,Math.round(value1)四舍五入函数,Math.floor(Math.ra
ndom()*(n+1))返回随机数
41.定义日期型变量:var today = new Date();
42.日期函数列表:dateObj.getTime()得到时间,dateObj.getYear()得到年份,dateObj.getFullYear()得到
四位的年份,dateObj.getMonth()得到月份,dateObj.getDate()得到日,dateObj.getDay()得到日期几,dat
eObj.getHours()得到小时,dateObj.getMinutes()得到分,dateObj.getSeconds()得到秒,dateObj.setTi
me(value)设置时间,dateObj.setYear(val)设置年,dateObj.setMonth(val)设置月,dateObj.setDate(va
l)设置日,dateObj.setDay(val)设置星期几,dateObj.setHours设置小时,dateObj.setMinutes(val)设置分,
dateObj.setSeconds(val)设置秒 [注意:此日期时间从0开始计]
43.FRAME的表示方式: [window.]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarN
ame,frameName.ObjFuncVarName
44.parent代表父亲对象,top代表最顶端对象
45.打开子窗口的父窗口为:opener
46.表示当前所属的位置:this
47.当在超链接中调用JS函数时用:(javascript :)来开头后面加函数名
48.在老的浏览器中不执行此JS:
49.引用一个文件式的JS:
50.指定在不支持脚本的浏览器显示的HTML:
51.当超链和onCLICK事件都有时,则老版本的浏览器转向a.html,否则转向b.html.例:dfsadf
52.JS的内建对象有:Array,Boolean,Date,Error,EvalError,Function,Math,Number,Object,RangeError,
ReferenceError,RegExp,String,SyntaxError,TypeError,URIError
53.JS中的换行:\n
54.窗口全屏大小:
55.JS中的all代表其下层的全部元素
56.JS中的焦点顺序:document.getElementByid("表单元素").tabIndex = 1
57.innerHTML的值是表单元素的值:如
"how are you"

,则innerHTML的值就是:how are you
58.innerTEXT的值和上面的一样,只不过不会把这种标记显示出来.
59.contentEditable可设置元素是否可被修改,isContentEditable返回是否可修改的状态.
60.isDisabled判断是否为禁止状态.disabled设置禁止状态
61.length取得长度,返回整型数值
62.addBehavior()是一种JS调用的外部函数文件其扩展名为.htc
63.window.focus()使当前的窗口在所有窗口之前.
64.blur()指失去焦点.与FOCUS()相反.
65.select()指元素为选中状态.
66.防止用户对文本框中输入文本:onfocus="this.blur()"
67.取出该元素在页面中出现的数量:document.all.tags("div(或其它HTML标记符)").length
68.JS中分为两种窗体输出:模态和非模态.window.showModaldialog(),window.showModeless()
69.状态栏文字的设置:window.status=‘文字‘,默认的状态栏文字设置:window.defaultStatus = ‘文字.‘;
70.添加到收藏夹:external.AddFavorite("http://www.dannyg.com"t;,"jaskdlf");
71.JS中遇到脚本错误时不做任何操作:window.onerror = doNothing; 指定错误句柄的语法为:window.on
error = handleError;
72.JS中指定当前打开窗口的父窗口:window.opener,支持opener.opener...的多重继续.
73.JS中的self指的是当前的窗口
74.JS中状态栏显示内容:window.status="内容"
75.JS中的top指的是框架集中最顶层的框架
76.JS中关闭当前的窗口:window.close();
77.JS中提出是否确认的框:if(confirm("Are you sure?"))else{alert("Not Ok");}
78.JS中的窗口重定向:window.navigate("http://www.sina.com.cn"t;);
79.JS中的打印:window.print()
80.JS中的提示输入框:window.prompt("message","defaultReply");
81.JS中的窗口滚动条:window.scroll(x,y)
82.JS中的窗口滚动到位置:window.scrollby
83.JS中设置时间间隔:setInterval("expr",msecDelay)或setInterval(funcRef,msecDelay)或setTimeou
t
84.JS中的模态显示在IE4+行,在NN中不行:showModalDialog("URL"[,arguments][,features]);
85.JS中的退出之前使用的句柄:function verifyClose(){event.returnValue="we really like you and ho
pe you will stay longer.";}} window.onbeforeunload=verifyClose;
86.当窗体第一次调用时使用的文件句柄:onload()
87.当窗体关闭时调用的文件句柄:onunload()
88.window.location的属性: protocol(http:),hostname(example.com),port(80),host(e
xample.com:80),pathname("/a/a.html"),hash("#giantGizmo",指跳转到相应的锚记),href(全部的信
息)
89.window.location.reload()刷新当前页面.
90.window.history.back()返回上一页,window.history.forward()返回下一页,window.history.go(返回
第几页,也可以使用访问过的URL)
91.document.write()不换行的输出,document.writeln()换行输出
92.document.body.noWrap=true;防止链接文字折行.
93.变量名.charAt(第几位),取该变量的第几位的字符.
94."abc".charCodeAt(第几个),返回第几个字符的ASCii码值.
95.字符串连接:string.concat(string2),或用+=进行连接
96.变量.indexOf("字符",起始位置),返回第一个出现的位置(从0开始计算)
97.string.lastIndexOf(searchString[,startIndex])最后一次出现的位置.
98.string.match(regExpression),判断字符是否匹配.
99.string.replace(regExpression,replaceString)替换现有字符串.
100.string.split(分隔符)返回一个数组存储值.
101.string.substr(start[,length])取从第几位到指定长度的字符串.
102.string.toLowerCase()使字符串全部变为小写.
103.string.toUpperCase()使全部字符变为大写.
104.parseInt(string[,radix(代表进制)])强制转换成整型.
105.parseFloat(string[,radix])强制转换成浮点型.
106.isNaN(变量):测试是否为数值型.
107.定义常量的关键字:const,定义变量的关键字:var
--------------------------------------------------------------------------------------------------------------------------------
javascript38种小技巧,推荐新手查看。
事件源对象
event.srcElement.tagName
event.srcElement.type
捕获释放
event.srcElement.setCapture();
event.srcElement.releaseCapture();
事件按键
event.keyCode
event.shiftKey
event.altKey
event.ctrlKey
事件返回值
event.returnValue
鼠标位置
event.x
event.y
窗体活动元素
document.activeElement
绑定事件
document.captureEvents(Event.KEYDOWN);
访问窗体元素
document.all("txt").focus();
document.all("txt").select();
窗体命令
document.execCommand
窗体COOKIE
document.cookie
菜单事件
document.oncontextmenu
创建元素
document.createElement("SPAN");
根据鼠标获得元素:
document.elementFromPoint(event.x,event.y).tagName=="TD
document.elementFromPoint(event.x,event.y).appendChild(ms)
窗体图片
document.images[索引]
窗体事件绑定
document.onmousedown=scrollwindow;
元素
document.窗体.elements[索引]
对象绑定事件
document.all.xxx.detachEvent(‘onclick‘,a);
插件数目
navigator.plugins
取变量类型
typeof($js_libpath) == "undefined"
下拉框
下拉框.options[索引]
下拉框.options.length
查找对象
document.getElementsByName("r1");
document.getElementById(id);
定时
timer=setInterval(‘scrollwindow()‘,delay);
clearInterval(timer);
UNCODE编码
escape() ,unescape
父对象
obj.parentElement(dhtml)
obj.parentNode(dom)
交换表的行
TableID.moveRow(2,1) document.all.csss.href = "a.css";
替换CSS

并排显示
display:inline
隐藏焦点
hidefocus=true
根据宽度换行
style="word-break:break-all"
自动刷新

简单邮件

快速转到位置
obj.scrollIntoView(true)


anchors
网页传递参数
location.search();
可编辑
obj.contenteditable=true
执行菜单命令
obj.execCommand
双字节字符
/[^\x00-\xff]/
汉字
/[\u4e00-\u9fa5]/
让英文字符串超出表格宽度自动换行
word-wrap: break-word; word-break: break-all;
透明背景

获得style内容
obj.style.cssText
HTML标签
document.documentElement.innerHTML
第一个style标签
document.styleSheets[0]
style标签里的第一个样式
document.styleSheets[0].rules[0]
防止点击空链接时,页面往往重置到页首端。
word
上一网页源
asp:
request.servervariables("HTTP_REFERER")
javascript:
document.referrer
释放内存
CollectGarbage();
禁止右键
document.oncontextmenu = function() { return false;}
禁止保存

禁止选取
地址栏图标

favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下
收藏栏图标

查看源码

关闭输入法

自动全选

ENTER键可以让光标移到下一个输入框

文本框的默认值

title换行
obj.title = "123sdfs "
获得时间所代表的微秒
var n1 = new Date("2004-10-10".replace(/-/g, "\/")).getTime()
窗口是否关闭
win.closed
checkbox扁平


获取选中内容
document.selection.createRange().duplicate().text
自动完成功能
打开该功能
关闭该功能
窗口最大化

无关闭按钮IE
window.open("aa.htm", "meizz", "fullscreen=7");
统一编码/解码
alert(decodeURIComponent(encodeURIComponent("http://你好.com?as= hehe")))
encodeURIComponent对":"、"/"、";" 和 "?"也编码
表格行指示

------------------------------------------------------------------------------------------------------------------------------------------------

核心(Core) Javascript 学习手记

核心(Core) Javascript 学习手记

linenum

CreateD BY STABX, AT 2006-9-5.

Javascript Notes By shawl.qiu

---/-------------------------------------------------------------

-3.1 函数比其他代码优先执行
-3. 优先级
-2.4 同时初始化多个变量并赋相同值
-2.3 在函数中使用 var 定义一个变量, 该变量将影响整个函数, 不分先后.
-2.2 全局变量与局部变量
-2.1.2 普通定义变量 2
-2.1.1 普通定义变量 1
-2.1 普通定义变量
-2. var 定义变量
-1.5 in 操作符
-1.4.2 true 等价 1, false 等价 0.
-1.4 == 与 ===
-1.4.1 NaN
-1.3 0/0=?
-1.2 类型转换
-1.1 -- 与 ++
-1.1.1
-1. 运算符

0. 语法
0.1 Switch

1. 按钮
1.1 前进后退按钮
1.2 确认按钮
1.3 最原始也最实用的 UBB 代码输入方法——SCRIPT & FORM
1.4 Prompt
1.5.1 鼠标经过时选中,并隐藏原框的文字, 移开再显示文字 ——文本框
1.5 鼠标经过时选中 ——复选框 Focus()
1.6 鼠标经过自动提交表单

2. 接收键盘事件
2.1 按任何键关闭窗口
2.2 实时显示更改的图片链接

3. 数组/Array
3.1 Javascript 结合 Asp 使用数组

4. 控制图片大小

5. 双击拷贝文本

6. IE 全屏显示

7. 文本框回车链接

8. 顯示頁面所有元素

9. 正则表达式

10. 接收鼠标事件
10.1 单击鼠标右击关闭窗口 (我用左手)
10.2 鼠标移过选择表单项

11. 字符串
11.1 检测字符串中是否出现某字符

12. 随机数
12.1.1 生成 GUID 2
12.1 生成 GUID

13. 时间操作
13.1 以毫秒为单位的倒计时跳转, 来源 CSDN

14. switch
14.1 简单 switch
15 if 判断
15.1.2 简单 if 判断 3
15.1.1 简单 if 判断 2
15.1 简单 if 判断
15.2 if 判断的 三个 写法
15.3 判断执行文件使用网络还是使用本地协议
15.4 if...else 写法

16. 简单 while

16. while

17. do while
17.1.2 简单 do while
17.1 简单 do while

18. for
18.1 简单 for
18.2 简单 for 1
18.3 循环列出从 a - z 的字母
18.3 n阶乘
18.4 Fibonacci Numbers

19. for in
19.1.1 简单 for in 1
19.1 简单 for in
19.2.1 for in 赋值 [数组] 1
19.2 for in 赋值 [数组]

20. try, catch, finally
20.1.1 简单 try, catch 1
20.1 简单 try, catch

21. with
21.1 简单with (另一写法)
21.1 简单 with

22. break, continue
22.1 continue
22.2.1 break 标签
22.2 break

23. call, apply
23.1.1 找出数组中最大的数
23.1 apply

24. object
24.1.1 创建简单对象 一
24.1.2 创建简单对象 二
24.1 创建简单对象
24.2.1 创建嵌套对象 1
24.2 创建嵌套对象
24.3 删除对象中的属性
24.4.1 遍历对象中的属性名 1
24.4 遍历对象中的属性名
24.5 obj.propertyIsEnumerable(‘ele‘)
24.6 obj.hasOwnProperty(‘ele‘)

25. toString
25.1 使用 toString 列出数组中的元素

26. Array()
26.0.1 简单创建数组, 并赋值 2
26.0 简单创建数组, 并赋值
26.0.3 创建数组中的数组
26.0.4 创建数组中的对象
26.0.2 简单创建数组
26.1 [array].push(), [array].pop()
26.2 数组排序
26.3 创建数组指定维数, 从 1 开始.

27. RegExp
27.1 普通操作 1
27.2 test 语句
27.3 exec 语句

28. new 语法

29. isNaN

30. Date()
30.1 输出年月日, 时分秒 的日期格式

31. function 函数
31.1.1.1 三种定义函数的方法 1.1
31.10 在数组中存储函数, 并引用
31.1.1 三种定义函数的方法 1
31.1.2 三种定义函数的方法 2
31.1 三种定义函数的方法
31.2 在标签中写函数
31.3 创建嵌套函数
31.4.1 创建递归函数 1
31.4 创建递归函数
31.5 创建 函数对象
31.6 在函数内部定义的函数只能在该函数内部调用
31.7 定义函数变量, 并赋值
31.8 变量引用函数
31.9 在对象中存储函数, 并引用
31.11 function.call()
31.12 在函数内定义的变量可以被下级内嵌函数调用

32. typeof 查看数据类型
32.1

33. obj.valueOf() 返回原始值

34. Math 对象
34.1.1 生成 1 至 4 的随机数
34.1 Math.random();
34.2 求 x 的 n 次方

35. delete

36. confirm() 确认框
36.1 带条件确认框

37. window.open

37. window
37.1 打开没有焦点的窗口

38. return 返回值
38.1 return true
38.2 return undefined

39. throw
39.1 简单产生错误

40. arguments
40.1 判断 arguments.length
40.2 列出所有 argument 的值
40.3 arguments.callee / 调用函数本身

41. .to******
41.1 toString

42. parseInt() / parseFolat()

--------------------------------

42. parseInt() / parseFolat()


41. .to******


41.1 toString




40. arguments

40.1 判断 arguments.length


40.2 列出所有 argument 的值


40.3 arguments.callee / 调用函数本身


39. throw

39.1 简单产生错误


38. return 返回值

38.1 return true


38.2 return undefined


37. window

37. window.open

37.1 打开没有焦点的窗口


36. confirm() 确认框

36.1 带条件确认框


35. delete


34. Math 对象

34.1 Math.random();

34.1.1 生成 1 至 4 的随机数


34.2 求 x 的 n 次方


33. obj.valueOf() 返回原始值


32. typeof 查看数据类型


32.1


31. function 函数

31.1 三种定义函数的方法


31.1.1 三种定义函数的方法 1


31.1.1.1 三种定义函数的方法 1.1


31.1.2 三种定义函数的方法 2


31.2 在标签中写函数
div 可用

div1 不可用

div2 可用

div3 可用


31.3 创建嵌套函数


31.4 创建递归函数
<%
var i=0;
function t(){
i++;
if(i<100){
Response.Write(i+‘
‘);
return t();
}
Response.Write(i+‘
‘);
}
t();
%>

31.4.1 创建递归函数 1


31.5 创建 函数对象


31.6 在函数内部定义的函数只能在该函数内部调用


31.7 定义函数变量, 并赋值


31.8 变量引用函数


31.9 在对象中存储函数, 并引用


31.10 在数组中存储函数, 并引用


31.11 function.call()


31.12 在函数内定义的变量可以被下级内嵌函数调用


30. Date()

30.1 输出年月日, 时分秒 的日期格式


29. isNaN


28. new 语法
new Boolean(false)
new Number(0)
new String("")
new Array()
new Object()
new Date();
new Error();

27. RegExp

27.1 普通操作 1


27.2 test 语句


27.3 exec 语句


26. Array()

26.0 简单创建数组, 并赋值


26.0.1 简单创建数组, 并赋值 2


26.0.2 简单创建数组


26.0.3 创建数组中的数组


26.0.4 创建数组中的对象


26.1 [array].push(), [array].pop()


26.2 数组排序


26.3 创建数组指定维数, 从 1 开始.


25. toString

25.1 使用 toString 列出数组中的元素


24. object

24.1 创建简单对象


24.1.1 创建简单对象 一


24.1.2 创建简单对象 二


24.2 创建嵌套对象


24.2.1 创建嵌套对象 1


24.3 删除对象中的属性


24.4 遍历对象中的属性名


24.4.1 遍历对象中的属性名 1


24.5 obj.propertyIsEnumerable(‘ele‘)


24.6 obj.hasOwnProperty(‘ele‘)


23. call, apply

23.1 apply

23.1.1 找出数组中最大的数


22. break, continue

22.1 continue


22.2 break

22.2.1 break 标签


21. with

21.1 简单 with


21.1 简单with (另一写法)
var $dw=document
$dw.write(‘ok this a test‘);

20. try, catch, finally

20.1 简单 try, catch
try{
5*kkk
}
catch(e){
alert(e)
}

20.1.1 简单 try, catch 1


19. for in

19.1 简单 for in


19.1.1 简单 for in 1
for (var $i in window){
document.write($i+‘
‘);
}

19.2 for in 赋值 [数组]
var $array=new Array();
var i=0;
for ($array[i++] in window){
//document.write($i+‘
‘);
}
alert($array[0]);

19.2.1 for in 赋值 [数组] 1


18. for

18.1 简单 for
for (var $i=0; $i<10; $i++) {
document.write($i)
}

18.2 简单 for 1
for (var $i=0, $j=10; $i<10; $i++, $j--) {
document.write(($i*$j)+‘
‘)
}

18.3 循环列出从 a - z 的字母


18.3 n阶乘


18.4 Fibonacci Numbers


17. do while

17.1 简单 do while
var $count=0
do{
document.write($count)
} while(++$count<10)

17.1.2 简单 do while
var $count=1
do{
document.write($count)
} while($count++<10)

16. while

16. 简单 while
var $count=0
while($count<10){ document.write($count);$count++;}

15 if 判断

15.1 简单 if 判断
function ubbTag(fId, str){
document.getElementById(fId).content.focus();
var strEnd=str.replace(/\[/ig,‘[/‘)
if (strEnd.indexOf(‘=‘)>-1){ strEnd=strEnd.replace(/(.*?)\=.*?\]/,‘$1]‘) }
if((document.selection)&&(document.selection.type== "Text")){
var oStr=document.selection.createRange();
oStr.text=str+oStr.text+strEnd
} else {
document.getElementById(fId).content.value+=str+strEnd
}
}

15.1.1 简单 if 判断 2


15.1.2 简单 if 判断 3


15.2 if 判断的 三个 写法


15.3 判断执行文件使用网络还是使用本地协议


15.4 if...else 写法


14. switch

14.1 简单 switch
/* switch(strEnd){
case ‘\[\/html]‘ :strEnd=strEnd.replace(/\\[\/,‘HTML 和 JS 代码支持[‘);break;
case ‘\[\/code]‘ :strEnd=strEnd.replace(/\\[\/,‘代码[‘);break;
case ‘\[\/quote]‘ :strEnd=strEnd.replace(/\\[\/,‘引用[‘);break;
case ‘\[\/cite]‘ :strEnd=strEnd.replace(/\\[\/,‘引用[‘);break;
case ‘\[\/linenum]‘ :strEnd=strEnd.replace(/\\[\/,‘显示行号[‘);break;
case ‘\[\/b]‘ :strEnd=strEnd.replace(/\\[\/,‘粗体[‘);break;
case ‘\[\/i]‘ :strEnd=strEnd.replace(/\\[\/,‘叙体[‘);break;
case ‘\[\/u]‘ :strEnd=strEnd.replace(/\\[\/,‘下划线[‘);break;
case ‘\[\/flash]‘ :strEnd=strEnd.replace(/\\[\/,‘Flash 动画[‘);break;
case ‘\[\/sound]‘ :strEnd=strEnd.replace(/\\[\/,‘背景声音[‘);break;
case ‘\[\/mms]‘ :strEnd=strEnd.replace(/\\[\/,‘WM格式流数据[‘);break;
case ‘\[\/rtsp]‘ :strEnd=strEnd.replace(/\\[\/,‘Real格式流数据[‘);break;
case ‘\[\/ra]‘ :strEnd=strEnd.replace(/\\[\/,‘在线Real Player播放音频文件[‘);break;
case ‘\[\/real]‘ :strEnd=strEnd.replace(/\\[\/,‘Real Player 播放视频文件[‘);break;
case ‘\[\/wm]‘ :strEnd=strEnd.replace(/\\[\/,‘在线Windows Media Player播放视频文件[‘);break;
case ‘\[\/wma]‘ :strEnd=strEnd.replace(/\\[\/,‘在线Windows Media Player播放音频文件[‘);break;
case ‘\[\/iframe]‘ :strEnd=strEnd.replace(/\\[\/,‘插入网页[‘);break;
} */

13. 时间操作

13.1 以毫秒为单位的倒计时跳转, 来源 CSDN


20.000 秒后 将自动跳转到

12. 随机数

12.1 生成 GUID





Untitled Document







12.1.1 生成 GUID 2





Untitled Document










11.1 检测字符串中是否出现某字符



11. 字符串

10.2 鼠标移过选择表单项
onMouseOver="focus();select();"

10.1 单击鼠标右击关闭窗口 (我用左手)


10. 接收鼠标事件

9. 正则表达式
function rbr() {
re=/\*/ig
document.all.textarea.value=document.all.textarea.value.replace(re,"")
}

8. 顯示頁面所有元素


7. 文本框回车链接

转到:

6. IE 全屏显示


5. 双击拷贝文本





4. 控制图片大小

//如果图片宽度大于 500px, 则 更改宽度为 500px

3.1 Javascript 结合 Asp 使用数组
<% ‘连接数据库
set rs=server.CreateObject("adodb.recordset") ‘创建 rs 数据查询
rs.open"Select a.*, b.* FROM ctglossarysubcat AS a INNER JOINctglossarysupercat AS b ON a.gcid = b.gcid order bya.gcid",MM_conn_string,1
%>

<%
rs.close ‘关闭 rs 连接
set rs=nothing
%>

3. 数组/Array

2.2 实时显示更改的图片链接
<%response.write sitename %>

2.1 按任何键关闭窗口


2. 接收键盘事件

1.6 鼠标经过自动提交表单
onMouseOut="submit()"

1.5.1 鼠标经过时选中,并隐藏原框的文字, 移开再显示文字 ——文本框




1.5 鼠标经过时选中 ——复选框 Focus()



1.4 Prompt
function prompter()
{

urlLink=window.prompt("请输入链接"," http://")
text = window.prompt("链接名")

if(text!="")
document.formT.content.value+=""+text+""
}


1.3 最原始也最实用的 UBB 代码输入方法——SCRIPT & FORM















1.2 确认按钮







1.1 前进后退按钮



1. 按钮

0. 语法

0.1 Switch
function kP() {
switch(event.keyCode) {
case 27: //按 ESC 键关闭窗口.
window.close()
break;
//case 120: //F9 转到主页
//window.location.href="/"
//break;
default:
break;
}
}

-1. 运算符

-1.1 -- 与 ++


-1.1.1


-1.2 类型转换


-1.3 0/0=?


-1.4 == 与 ===

-1.4.1 NaN


-1.4.2 true 等价 1, false 等价 0.


-1.5 in 操作符


-2. var 定义变量

-2.1 普通定义变量


-2.1.1 普通定义变量 1


-2.1.2 普通定义变量 2


-2.2 全局变量与局部变量


-2.3 在函数中使用 var 定义一个变量, 该变量将影响整个函数, 不分先后.
var scope = "global";
function f( ) {
alert(scope); // Displays "undefined", not "global"
var scope = "local"; // Variable initialized here, but defined everywhere
alert(scope); // Displays "local"
}
f( );

-2.4 同时初始化多个变量并赋相同值


-3. 优先级

-3.1 函数比其他代码优先执行


---/---------------------------------------------------------

常用参数

3. document

2. location

1. this

---------------------------------

3.3 写出字符串
document.write("");

3.2 document.from
指定 表单域

3.1 document.all.id
查找指定 HTML 页面 ID 或 名字

3. document

2.2 转到特定网页
onClick="location.href=‘ http://127.0.0.1/‘"

2.1 单独 location
取页面地址

2. location

1.4 this.height
取高度属性

1.3 this.width
取宽度属性

1.2 this.href
取链接地址

1.1 this.src
取图片地址

1. this

---/---------------------------------------------------------

问题集:

3. return 返回多个值 2006-10-14 14:13:18

2. 理解 setInternal 用法

1. 理解 void 用法

---/---------------------------------------------------------

相关摘要:

24.Keep in mind that the function statement is available in all versionsof JavaScript, the Function( ) constructor is available only inJavaScript 1.1 and later, and function literals are available only inJavaScript 1.2 and later. Recall that we said the three functionsdefined earlier are "more or less" equivalent -- there are somedifferences between these three techniques for function definition,which we‘ll consider in Section 11.5.

//JavaScript: The Definitive Guide, 4th Edition -- 7.1.3 Function Literals
2006-10-19 14:35:56

23.The Function( ) constructor expects any number of string arguments. Thelast argument is the body of the function -- it can contain arbitraryJavaScript statements, separated from each other by semicolons. Allother arguments to the constructor are strings that specify the namesof the parameters to the function being defined. If you are defining afunction that takes no arguments, you simply pass a single string --the function body -- to the constructor.

//JavaScript: The Definitive Guide, 4th Edition -- 7.1.2 The Function( ) Constructor
2006-10-19 14:16:18

22.Note that ECMAScript v3 does not allow function definitions to appearanywhere; they are still restricted to top-level global code andtop-level function code. This means that function definitions may notappear within loops or conditionals, for example.[1] These restrictionson function definitions apply only to function declarations with thefunction statement. As we‘ll discuss later in this chapter, functionliterals (another feature introduced in JavaScript 1.2 and standardizedby ECMAScript v3) may appear within any JavaScript e­xpression, whichmeans that they can appear within if and other statements.

//JavaScript: The Definitive Guide, 4th Edition -- 7.1 Defining and Invoking Functions
2006-10-19 14:10:13

21.try and finally can be used together without a catch clause. In thiscase, the finally block is simply cleanup code that is guaranteed to beexecuted, regardless of any break, continue, or return statementswithin the try clause. For example, the following code uses atry/finally statement to ensure that a loop counter variable isincremented at the end of each iteration, even when an iterationterminates abruptly because of a continue statement:

//JavaScript: The Definitive Guide, 4th Edition -- 6.17 try/catch/finally
2006-10-18 19:18:08

20.The continue statement, in both its labeled and unlabeled forms, can beused only within the body of a while, do/while, for, or for/in loop.Using it anywhere else causes a syntax error.

//JavaScript: The Definitive Guide, 4th Edition -- 6.12 continue
2006-10-18 16:03:46

19. The following rules are used to determine whether two values are identical according to the === operator:

If the two values have different types, they are not identical.

Ifboth values are numbers and have the same value, they are identical,unless either or both values are NaN, in which case they are notidentical. The NaN value is never identical to any other value,including itself! To check whether a value is NaN, use the globalisNaN( ) function.

If both values are strings and containexactly 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 wayto encode the same string. For efficiency, however, JavaScript stringcomparison compares strictly on a character-by-character basis, and itassumes that all strings have been converted to a "normalized form"before they are compared. See the "String.localeCompare( )" referencepage in the core reference section of this book for another way tocompare strings.

If both values are the boolean value true or both are the boolean value false, they are identical.

Ifboth values refer to the same object, array, or function, they areidentical. If they refer to different objects (or arrays or functions)they are not identical, even if both objects have identical propertiesor both arrays have identical elements.

If both values are null or both values are undefined, they are identical.

The following rules are used to determine whether two values are equal according to the == operator:

Ifthe two values have the same type, test them for identity. If thevalues are identical, they are equal; if they are not identical, theyare not equal.

If the two values do not have the same type,they may still be equal. Use the following rules and type conversionsto check for equality:

If one value is null and the other is undefined, they are equal.

Ifone value is a number and the other is a string, convert the string toa number and try the comparison again, using the converted value.

Ifeither value is true, convert it to 1 and try the comparison again. Ifeither value is false, convert it to 0 and try the comparison again.

Ifone value is an object and the other is a number or string, convert theobject to a primitive and try the comparison again. An object isconverted to a primitive value by either its toString( ) method or itsvalueOf( ) method. The built-in classes of core JavaScript attemptvalueOf( ) conversion before toString( ) conversion, except for theDate class, which performs toString( ) conversion. Objects that are notpart of core JavaScript may convert themselves to primitive values inan implementation-defined way.

Any other combinations of values are not equal.

As an example of testing for equality, consider the comparison:
"1" == true

Thise­xpression evaluates to true, indicating that these verydifferent-looking values are in fact equal. The boolean value true isfirst converted to the number 1, and the comparison is done again.Next, the string "1" is converted to the number 1. Since both numbersare now the same, the comparison returns true.

When theequality operator in JavaScript 1.1 attempted to convert a string to anumber and failed, it displayed an error message noting that the stringcould not be converted, instead of converting the string to NaN andreturning false as the result of the comparison. This bug has beenfixed in JavaScript 1.2.

//JavaScript: The Definitive Guide, 4th Edition -- 5.4 Equality Operators
2006-10-16 21:56:30

18.In top-level code (i.e., JavaScript code that is not part of afunction), you can use the JavaScript keyword this to refer to theglobal object. Within functions, this has a different use, which isdescribed in Chapter 7.

//JavaScript: The Definitive Guide, 4th Edition -- 4.6 Variables as Properties
2006-10-16 16:08:34

17.Garbage collection is automatic and is invisible to the programmer. Youcan create all the garbage objects you want, and the system will cleanup after you! You need to know only enough about garbage collection totrust that it works; you don‘t have to wonder about where all the oldobjects go. For those who aren‘t satisfied, however, Section 11.3,contains further details on the JavaScript garbage-collection process.

//JavaScript: The Definitive Guide, 4th Edition -- 4.5 Garbage Collection
2006-10-16 16:01:55

16. Primitive Types and Reference Types
var a = [1,2,3]; // Initialize a variable to refer to an array
var b = a; // Copy that reference into a new variable
a[0] = 99; // Modify the array using the original reference
alert(b); // Display the changed array [99,2,3] using the new reference

Ifthis result does not seem surprising to you, you‘re already wellfamiliar with the distinction between primitive and reference types. Ifit does seem surprising, take a closer look at the second line. Notethat it is the reference to the array value, not the array itself, thatis being assigned in this statement. After that second line of code, westill have only one array object; we just happen to have two referencesto it.

//JavaScript: The Definitive Guide, 4th Edition -- 4.4 Primitive Types and Reference Types

15. 在任何情况下,如果六个月以后您还能毫不费力地阅读和理解所编写的代码,则说明这些代码写得不错。

//Windows 脚本技术 -- JScript -- 什么是 JScript?
2006-10-16 14:12:55

14.The rule that all variables declared in a function are definedthroughout the function can cause surprising results. The followingcode illustrates this:

var scope = "global";
function f( ) {
alert(scope); // Displays "undefined", not "global"
var scope = "local"; // Variable initialized here, but defined everywhere
alert(scope); // Displays "local"
}
f( );
//JavaScript: The Definitive Guide, 4th Edition -- 4.3 Variable Scope

13. Variable Scope
Thescope of a variable is the region of your program in which it isdefined. A global variable has global scope -- it is defined everywherein your JavaScript code. On the other hand, variables declared within afunction are defined only within the body of the function. They arelocal variables and have local scope. Function parameters also count aslocal variables and are defined only within the body of the function.
Withinthe body of a function, a local variable takes precedence over a globalvariable with the same name. If you declare a local variable orfunction parameter with the same name as a global variable, youeffectively hide the global variable. For example, the following codeprints the word "local":

var scope = "global"; // Declare a global variable
function checkscope( ) {
var scope = "local"; // Declare a local variable with the same name
document.write(scope); // Use the local variable, not the global one
}
checkscope( ); // Prints "local"

//JavaScript: The Definitive Guide, 4th Edition -- 4.3 Variable Scope
2006-10-16 1:11:59

12.In general, functions do not know what variables are defined in theglobal scope or what they are being used for. Thus, if a function usesa global variable instead of a local one, it runs the risk of changinga value upon which some other part of the program relies. Fortunately,avoiding this problem is simple: declare all variables with var

//JavaScript: The Definitive Guide, 4th Edition -- 4.3 Variable Scope
2006-10-15 22:23:32

11.If you attempt to read the value of an undeclared variable, JavaScriptwill generate an error. If you assign a value to a variable that youhave not declared with var, JavaScript will implicitly declare thatvariable for you. Note, however, that implicitly declared variables arealways created as global variables, even if they are used within thebody of a function. To prevent the creation of a global variable (orthe use of an existing global variable) when you meant to create alocal variable for use within a single function, you must always usethe var statement within function bodies. It‘s best to use var for allvariables, whether global or local. (The distinction between local andglobal variables is explored in more detail in the next section.)

//JavaScript: The Definitive Guide, 4th Edition -- 4.2.1 Repeated and Omitted Declarations
2006-10-15 22:00:53

10. Error Objects

ECMAScriptv3 defines a number of classes that represent errors. The JavaScriptinterpreter "throws" an object of one of these types when a runtimeerror occurs. (See the throw and try statements in Chapter 6 for adiscussion of throwing and catching errors.) Each error object has amessage property that contains an implementation-specific errormessage. The types of predefined error objects are Error, EvalError,RangeError, ReferenceError, SyntaxError, TypeError, and URIError. Youcan find out more about these classes in the core reference section ofthis book.

//JavaScript: The Definitive Guide, 4th Edition -- 3.11 Error Objects
2006-10-15 19:39:08

9. undefined

Anotherspecial value used occasionally by JavaScript is the undefined valuereturned when you use either a variable that has been declared butnever had a value assigned to it, or an object property that does notexist. Note that this special undefined value is not the same as null.

Althoughnull and the undefined value are distinct, the == equality operatorconsiders them to be equal to one another. Consider the following:
my.prop == null

//JavaScript: The Definitive Guide, 4th Edition -- 3.8 undefined
2006-10-15 18:02:39

8. The way to really learn a new programming language is to write programs with it.

//JavaScript: The Definitive Guide, 4th Edition -- 1.10 Exploring JavaScript
2006-10-14 2:40:02

7.Both Netscape and Microsoft have made their JavaScript interpretersavailable to companies and programmers who want to embed them in theirapplications. Netscape‘s interpreter was released as open source and isnow available through the Mozilla organization (see http://www.mozilla.org/js/).Mozilla actually provides two different versions of the JavaScript 1.5interpreter. One is written in C and is called "SpiderMonkey." Theother is written in Java and, in a flattering reference to this book,is called "Rhino."

//JavaScript: The Definitive Guide, 4th Edition -- 1.4 JavaScript in Other Contexts
2006-10-14 1:13:44

6. 11.1.2 Explicit Type Conversions

Table11-1 listed the automatic data type conversions that JavaScriptperforms. It is also possible to explicitly convert values from onetype to another. JavaScript does not define a cast operator as C, C++,and Java do, but it does provide similar facilities for converting datavalues.

As of JavaScript 1.1 (and the ECMA-262 standard),Number( ) , Boolean( ), String( ), and Object( ) may be called asfunctions as well as being invoked as constructors. When invoked inthis way, these functions attempt to convert their arguments to theappropriate type. For example, you could convert any value x to astring with String(x) and convert any value y to an object withObject(y).

There are a few other tricks that can be useful forperforming explicit conversions. To convert a value to a string,concatenate it with the empty string:
var x_as_string = x + "";

To force a value to a number, subtract zero from it:
var x_as_number = x - 0;

And to force a value to boolean, use the ! operator twice:
var x_as_boolean = !!x;

Becauseof JavaScript‘s tendency to automatically convert data to whatever typeis required, explicit conversions are usually unnecessary. They areoccasionally helpful, however, and can also be used to make your codeclearer and more precise.

//JavaScript: The Definitive Guide, 4th Edition -- 11.1 Data Type Conversion
2006-10-12 12:36:23

5.Each RegExp object has five properties. The source property is aread-only string that contains the text of the regular e­xpression. Theglobal property is a read-only boolean value that specifies whether theregular e­xpression has the g flag. The ignoreCase property is aread-only boolean value that specifies whether the regular e­xpressionhas the i flag. The multiline property is a read-only boolean valuethat specifies whether the regular e­xpression has the m flag. Thefinal property is lastIndex, a read-write integer. For patterns withthe g flag, this property stores the position in the string at whichthe next search is to begin. It is used by the exec( ) and test( )methods, as described in the previous section.

//JavaScript: The Definitive Guide, 4th Edition -- 10.3.2 RegExp Instance Properties
2006-10-9 21:23:26

4.the RegExp constructor. search( ) does not support global searches --it ignores the g flag of its regular e­xpression argument.

//JavaScript: The Definitive Guide, 4th Edition -- 10.2 String Methods for Pattern Matching
2006-10-9 19:56:40

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 usedwith arrays, to access these properties. Thus, the following twoJavaScript e­xpressions have the same value:

object.property
object["property"]

//JavaScript: The Definitive Guide, 4th Edition -- 8.6 Objects as Associative Arrays
2006-10-9 14:45:13

2. The typeof Operator

typeofis a unary operator that is placed before its single operand, which canbe of any type. Its value is a string indicating the data type of theoperand.

The typeof operator evaluates to "number", "string",or "boolean" if its operand is a number, string, or boolean value. Itevaluates to "object" for objects, arrays, and (surprisingly) null. Itevaluates to "function" for function operands and to "undefined" if theoperand is undefined.
//JavaScript: The Definitive Guide, 4th Edition -- 5.10.2 The typeof Operator

1. JavaScript strings (and JavaScript arrays, as we‘ll see later) are indexed starting with zero.


---/---------------------------------------------------------

小小心得

1. 花括弧定义 对象 元素, 方括弧定义 数组 元素. 2006-10-15 17:55:50

2. Javascript 正则表达式摘要

linenum
Javascript 与正则表达式 By shawl.qiu


语法方法:

5. str.split()


4. str.match()


3. str.replace()


2. str.search()


1. 子匹配


0. 创建正则表达式模式

0.1 new RegExp()


-1. re.exec(str)


-2. re.test(str)


---/----------------------------------------

摘要:

4.The String methods search( ) , replace( ), and match( ) do not use thelastIndex property as exec( ) and test( ) do. In fact, the Stringmethods simply reset lastIndex( ) to 0. If you use exec( ) or test( )on a pattern that has the g flag set and you are searching multiplestrings, you must either find all the matches in each string, so thatlastIndex is automatically reset to zero (this happens when the lastsearch fails), or you must explicitly set the lastIndex property to 0yourself. If you forget to do this, you may start searching a newstring at some arbitrary position within the string rather than fromthe beginning. Finally, remember that this special lastIndex behavioroccurs only for regular e­xpressions with the g flag. exec( ) and test() ignore the lastIndex property of RegExp objects that do not have theg flag.

//JavaScript: The Definitive Guide, 4th Edition -- 10.3.1 RegExp Methods for Pattern Matching
2006-10-20 18:10:36

3. match method
Thematch( ) method is the most general of the String regular e­xpressionmethods. It takes a regular e­xpression as its only argument (orconverts its argument to a regular e­xpression by passing it to theRegExp( ) constructor) and returns an array that contains the resultsof the match. If the regular e­xpression has the g flag set, the methodreturns an array of all matches that appear in the string. For example:
"1 plus 2 equals 3".match(/\d+/g) // returns ["1", "2", "3"]

//JavaScript: The Definitive Guide, 4th Edition -- 10.2 String Methods for Pattern Matching
2006-10-20 17:23:08

2. search method
Stringssupport four methods that make use of regular e­xpressions. Thesimplest is search( ). This method takes a regular e­xpression argumentand returns either the character position of the start of the firstmatching substring, or -1 if there is no match. For example, thefollowing call returns 4:
"JavaScript".search(/script/i);

Ifthe argument to search( ) is not a regular e­xpression, it is firstconverted to one by passing it to the RegExp constructor. search( )does not support global searches -- it ignores the g flag of itsregular e­xpression argument.

//JavaScript: The Definitive Guide, 4th Edition -- 10.2 String Methods for Pattern Matching

1. A number of punctuation characters have special meanings in regular e­xpressions. They are:
^ $ . * + ? = ! : | \ / ( ) [ ] { }
//JavaScript: The Definitive Guide, 4th Edition -- 10.1 Defining Regular Expressions