javascript 学习笔记7-14章

7.8 Specila Operators
1. ?:
(a>b? 'greater':'smaller')

2. comma operator
<script>
 for(s=10,y=1;x>=1;x--,y++)
{
 for(a=x;a>=1;a--){ document.write('S');}
 for(b=1;b<=y;b++){ document.write('T');}
 document.write("<br>");
}
</script>


3. delete operator

4. new operator
   new Array()
   new Date()

5. this operator
   this 可用来代表当时工作的对象,一般有这语法:
   this.property


6. typeof operator
   typeof 是用来传回一个operand(操作数)的类别,有以下语法
   typeof(operand)

7. void operator
   不传回值

7.9 Operators的优先级
++ -- ~ !
* / %
+ -
<< >>
< > <= >=
== !=
*
^
|
&&
||
=


8.4 Array的methods
1. arrayName.concat()
   是用来连结两个array
colors1=new Array("red","green","blue")
colors2=new Array("white","black","yellow")
colors3=colors1.concat(colors2)

2. arrayName.join()
   用来将一列array的成员变为文字
colors1=new Array("red","green","blue")
x=colors1.join()          red,green,blue
x=colors1.join("+")       red+green+blue

3. arrayName.pop()
   将最后一个成员挑出,并传回这成员的名称,array的length也缩少一个

4. arrayName.push()
   是这在array之尾加上新成员,length也自动加长,若新加多个成员,push()会传回最后的一个成员的名称

5. arrayName.reverse()
   这是用来将一个array倒排,新数组放回原有名称内

6. arrayName.shift()
   这是将第一个成员挑出,并传回该成员的名单。与pop()相似,不同的是pop()挑去最后一个成员。shift()挑去第一个。

7. arrayName.slice()
   是将一个array内一列成员抽出,并传回一个新的array,原有的array不变,语法是newArray=arrayName.slice(begin,end)

8. arrayName.splice()
   是用来在一个数组中加进新成员,或减去已有的成员,利用这method,我们可以在一个数组中,将已使用过的一个成员人数组名单中踢走,就不会重复使用一个名单。splice()有以下语法:
   splice(编号,多少个,"新成员1",...,"新成员n")
   "编号"是在数组中开始变更(加或减)的位置,例如在colors数组中,编号5表示在colors[5]这位置开始加进或减去成员。
   “多少个”是删去已有的成员数目,若这数目是0则不删去,这情况下需发在后指明加进新成员。这splice()会传回删去成员名单,但也可不理会这项操作。
    “新成员1”,...,"新成员n"表示要加进的新成员名单。

9. arrayName.sort()
   用来将一个数组根据字母来排序,排序后的数组放回原有的名称内。

10. arrayName.toString()
   将一个数组(或一个地象名称)变为文字,并造出一个新的文字对象,原有数组不变。

11. arrayName.unshift()
   在数组中首位置加进一或多个成员,并传回该数组的新长度,语法是:
   arrayName.unshift("新成员1",...,"新成员n")


第9章 document object
9.1 document的method
window->document->(anchor,applet,area,image,layer,link,plugin,form)

1. document.write()
2. document.writeln()
3. document.open() document.close()

msgWin=window.open("","","width=400,height=200")
msgWin=document.open()                          用来在窗格或子窗口开启一个网页
msgWin.document.write("Good Morning")           将数据写在这个网页内
msgWin.document.close()                         最后关闭这个窗口

9.2 document 的 property
bgColor 网页的背景色
fgColor 网页的文字色
linkColor 末用的连结的文件色
alinkColor 在选择中的连结(alink)的文字色
vlinkColor 已使用的连结的文字色

lastModified 网的最后存档日期 (read-only)
referrer 转介过来的URL (read-only)
domain  供应网页的服务器的domain name (read-only)
URL 目前网页的URL(read-only)
cookie 阅读及设定cookie
title 网页的title (read-only)

anchors 书签数组 (read-only)
applets 网页中applets的数组 (read-only)
embeds  网页中<embed>的数组 (read-only)
forms   form的数组 (read-only)
images  网页中图片的数组 (read-only)
layers  网页中layers的数组 (read-only)
links   连结数组 (read-only)
plugins 网页中plugins的数组 (read-only)

9.5 navigator object
  navigator object 可用来检查观看者的浏览器的一些数据,例如可分辨浏览器是Netscape或IE,与及使用的版本。
navigator.appCodeName 浏览器的产品代号名称
navigator.appName     浏览器名称
navigator.appVersion  浏览器的版本(version)
navigator.language    浏览器的语系
navigator.userAgent   浏览器及操作系统的各项数据。


第10章 setTimeout()
10.1 setTimeout()
<script>
x=0;
function countSecond()
{
 x=x+1;
 x=x%60;
 document.fm.displayBox.value=x;
 setTimeout("countSecond()",1000);
}
</script>


10.2 clearTimeout()
当一个setTimeout()开始了循环的工作,我们要使它停下来,可使用clearTimeout()这个method
timeoutID=setTimeout("count1()",1000);
clearTimeout(timeoutID);


10.3 set flag
设定一个旗织,使用只能启动一次。
<head>
<script>
x=0;
flag=0;
function countSecond()
{
 x=x+1;
 x=x%60;
 document.fm.displayBox.value=x;
 count=setTimeout("countSecond()",1000);
 flag=1;
}
function restart()
{
 if(flag==0)
 {
   countSecond();
 }
}
</script>
</head>
<body>
<form id="fm" name="form1" method="post" action="">
  <label>
  <input type="text" name="displayBox" id="displayBox" />
  </label>
  <label>
  <input type="button" name="stop" id="stop" value="停止" onclick="clearTimeout(count); flag=0;"/>
  <input type="button" name="start" id="start" value="开始" onclick="restart();"/>
  </label>
</form>
</body>


第11章 Event handlers
在一些event handler中,引发一个function(或method)时,若这function传回true值,这event handler会如常操作,若传回false值,这event handler会取消。

11.2 focus() 及select()
document.fm.tx.focus() //将focus放进文字框内
document.fm.tx.select() //选定文字框内的文字

 

11.3 个别 event handler说明
1. onAbort 中断 是用于image这对象,当浏览器加载一幅图片时,若观看者按[停止]按钮,或转去另一个网页,因此中止加载该图片,就会引发onAbort所设定的反应。
<img src="welcome.gif" onAbort="alert('the picture has failed to load completely.')">

2. onBlur 离开焦点
   onFocus获取焦点

3. onChange
   当鼠标指针移离一个select,text,或textarea的组件,若组件的内容曾改变,就会引发onChange所设定的反应。

4. onClick

   onClick接受传回的true/false值

5. onDblClick
   这是连按两下鼠标键所引发的反应。

6. onKeyDown
   这是在键盘按下一个键所引发的反应。

7. onKeyPress按下一个键
   onPress 放开该键

8. onLoad 是加载网页或图像的event

9. onMouseDown 按下鼠标
   onMouseUp   放开鼠标

10. onMouseOver 鼠标移上
    onMouseOut  鼠标移开

11. onReset
    是观看者按下重置的按钮,这会将form内已输入的数据清除,回复默认值。

12. onResize
    是观看者改变浏览器窗口的大小。

13. onSelect
    是指观看者在text或textarea中选定了一些文字,使用onSelect可设定这event的反应。

14. onSubmit
    在form的设定,通常会有一个submit(送出数据)的按钮,观看者在form中输入数据后,按这按钮(这event就是submit),资料就会送出,我们可以使用onSubmit来设定资料送出前的一些反应,通常是将数据作初步验证(validation),例如核对是否有些文字框末输入数据,电话号码是否8个数字,又或电邮地址是否有@这符号。

15. onUnload
    当一个网页转去另一个网页,载入新网页就是load,取消旧网页就是Unload.

11.4 自订的event

<script>
 document.pic2.onmouseover=showeat
 function showeat() {document.pic1.src='cat.jpg'}
</script>


第12章 String object
12.1 String object 及 length property
x=new String("Good Morning")
x.length
x[4]----d


12.2 产生文字格式的method

str="Good Morning"
document.write(str.method())

stringName.big()      产生大一级字
stringName.blink()    产生闪动字
stringName.bold()     产生粗体字
stringName.fixed()    产生固定字宽字体
stringName.italics()  产生斜体字
stringName.small()    产生细一级字
stringName.strike()   字中加上删除线
stringname.sub()      产生下标字
stringName.sup()      产生下标字

stringName.fontcolor() 指定字的颜色
stringName.fontcolor("red")

stringName.fontsize(12) 指定字的大小

stringName.toLowerCase() 将字变为全小写

stringName.toUpperCase() 将字变为全大写


12.3 String 内的文字控制
1.stringName.charAt(index)
返回字符中某个字符,index从0开始的.

2.stringName.charCodeAt(index)
传回的不是字符,而是该字符的ASCII骗码

3.stringName.concat()
这是用来连结两个字符串,有这语法:
x=string1.concat(string2)

4. String.fromCharCode()
用来将ASCII编码变为字符,如65变为A

5. stringName.indexOf()
用来传回一个或一组字符(是为value)首次在一个字符串中出现的排序位置,有以下语法
str.indexOf("searchValue",fromIndex)

6. 复式 if ... else statement

7. stringName.lastIndexOf()
   与indexOf()相似,但传回的是字符串中最后个找到的value

8. stringName.slice()
   用来抽取一个字符串某部分,变成另一个新字符串,有以下语法
   str.slice(开始位置,停止位置)

9. stringName.substr()
   用来抽取一个字符串某个长度的字符,变成另一个新字符串,有以下语法:
   str.substr(开始位置,字符数目)

10. stringName.substring()
    功能及语法和slice()相同

11. match(),search(),及replace()
    功能主要是与regular expression合并使用

    str.match("目标字")
    str是有关的字符串,目标字是要在这字符串内寻找的文字,找到就传回目标字,找不到就传回null这一个字

    str.search("目标字")
    str是有关的字符串,目标字是要在这字符串内寻找的文字,找到就传回目标字的排序位置,找不到就传回-1

    str.replace("目标字","代替字")
    str是有关的字符串,"目标字"是要在字字符串内寻找的文字,找到就用"代替字"来取代并传回新的字符串,原有字符串不变.

 

第13章 Form and Validation

13.1  Form object
1 form 的用途
(1)造出文字框或按钮作为操作工具,例如用按钮来启动function或method
(2)设定一些可让观看者输入数据的组件,例如文字框,下拉式选项,圆钮选项等等.
(3)使用submit的功能将观看者的选择或填入的数据送回指定的地址.


13.3 各类<input>组件
    使用<input type="组件类别">可以设定以下各项组件
1. type=text 文字文本框
2. type=password 密码文本框
3. type=radio  圆钮选项
4. type=checkbox 核选方块
5. type=button 按钮
6. type=submit 送出数据的按钮
7. type=reset  清除数据的按钮
   若<input>内无指定类别,就是使用 type=text (默认值)

13.4 <select> 的语法
 <select>是用来造出下拉选项(pull-down menu) ,有以下语法
<select name="对象名称" size="数值" multiple><option value="送出的名称">

13.5 <textarea> 的语法
  <textarea>(卷动文字方块)是设定一个文字区,让观看者可输入较多的数据,有以下语法:
<textarea name="对象名称" rows="行数" cols="栏数">
 
name=是设定这文字区的对象名称,大小用rows=(行)及 cols=(栏,columns)来设定,这标签要用</textarea>来结束,如下
<textarea name="address" rows=4 cols=40>
请在这处输入你的地址....
</textarea>


第14章 Date object

14.1 产生Date object 的方法

today=new Date()
specialDay=new Date("dec 25,2000")

我们要指定一个Date object的时间值,可使用以下的格式
new Date("month day,year hours:minutes:seconds")

new Date(yr_num,mo_num,day_num,hr_num,min_num,sec_num)

14.2 显示Date object内某项资料
1. dateName.getYear() --- 99 或 2000
2. dateName.getMonth() --- 0-11
3. dateName.getDay() --- 0-6
4. dateName.getDate() ---1-31
5. dateName.getHours() --- 0-23
6. dateName.getMinutes() --- 0-59
7. dateName.getSeconds() --- 0-59
8. dateName.getTime() --- 单位是毫秒

xmas=new Date("Dec 25,2000")
now=new Date("Oct 20,2000")
interval=(xmas.getTime()-now.getTime())/1000/60/60/24 天

例如
<script>
showDay=new Array("周日","周一","周二","周三","周四","周五","周六")
x=(new Date()).getDay()
document.write("今天是"+showDay[x]+",对码?")
</script>


14.3 设定时间值内某项数据
1. dateName.setDate() --- 1-31
2. dateName.setYear() --- 98 或 2009
3. dateName.setMonth() --- 0-11
4. dateName.setHours() ---0-23
   dateName.setMinutes() --- 0-59
   dateName.setSeconds() --- 0-59
5. dateName.setTime() --- 毫秒


14.4 特别时间显示格式

1. dateName.getTimezoneOffset()
   传回本地时间与GMT 的时差,单位是分钟

2. Date.parse()
   用来接受一个文字式的时间,然后计算由1970/1/1至这时间有多少微秒
   Date.parse("12 mar 2000")

3. dateName.toGMTString()
   将一个时间变为Internet上习惯的GMT格式
   Thu,9 Mar 2000 07:33:00 UTC

4. dateName.toLocaleString()
   将时间变为我们日常用的格式
   03/07/1999 02:40:12


 

posted @ 2009-06-18 15:06  teacherzj  阅读(205)  评论(0编辑  收藏  举报