posts - 134,  comments - 22,  trackbacks - 0

 

都是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("input").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 expression];[condition];[upadte expression]) {inside loop}
16.
中止的命令是:
break
17.JS
中的函数定:
function functionName([parameter],...){statement[s]}
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<form.elements.length;i ){
if (form.elements.type == "text"){
form.elements.value = "";
}
}
31.
复选JS中判断是否:
document.forms[0].checkThis.checked
(checked
属性代表是否中返回TRUEFALSE)
32.
单选钮组(单选的名称必相同):
单选钮组document.forms[0].groupName.length
33.
单选钮组判断是否被中也是用checked.
34.
下拉列表框的:
document.forms[0].selectName.options[n].value
(n
用下拉列表框名称加上.selectedIndex来确定被中的)
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.random()*(n 1))
返回随机数
41.
日期型:
var today = new Date();
42.
日期函数列表:
dateObj.getTime()
得到时间,dateObj.getYear()得到年份,dateObj.getFullYear()得到四位的年份,
dateObj.getMonth()
得到月份,dateObj.getDate()得到日,dateObj.getDay()得到日期几,
dateObj.getHours()
得到小,dateObj.getMinutes()得到分,dateObj.getSeconds()得到秒,
dateObj.setTime(value)
时间,dateObj.setYear(val)置年,
dateObj.setMonth(val)
置月,dateObj.setDate(val)置日,
dateObj.setDay(val)
置星期几,dateObj.setHours置小,dateObj.setMinutes(val)置分,
dateObj.setSeconds(val)
[注意:此日期时间0]
43.FRAME
的表示方式:
[window.]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarName,frameName.ObjFuncVarName
44.parent
代表父亲对,top代表最
45.
子窗口的父窗口:opener
46.
表示当前所属的位置:this
47.
当在超接中JS函数:(javascript :)开头后面加函数名
48.
在老的浏览器中不行此JS:<!-- //-->
49.
引用一个文件式的JS:<script type="text/javascript" src="aaa.js"></script>
50.
指定在不支持脚本的浏览示的HTML:<noscript></noscript>
51.
当超onCLICK事件都有,老版本的浏览a.html,则转b.html.
:<a href="a.html" onclick="location.href='b.html';return false">dfsadf</a>
52.JS
的内建象有:
Array,Boolean,Date,Error,EvalError,
Function,Math,Number,Object,RangeError,ReferenceError,
RegExp,String,SyntaxError,TypeError,URIError
53.JS
中的:\n
54.
窗口全屏大小:
<script>function fullScreen(){ this.moveTo(0,0);this.outerWidth=screen.availWidth;
this.outerHeight=screen.availHeight;}window.maximize=fullScreen;</script>
55.JS
中的all代表其下的全部元素
56.JS
中的焦点:document.getElementByid("元素").tabIndex = 1
57.innerHTML
是表元素的:
<p id="para">"how are <em>you</em>"</p>,innerHTML就是:how are <em>you</em>
58.innerTEXT
和上面的一,只不不会把<em>这种标记显示出来.
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";,"jaskdlf");
71.JS
中遇到脚本错误时不做任何操作:
window.onerror = doNothing;
指定错误句柄的:window.onerror = 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?")){alert("ok");}else{alert("Not Ok");}
78.JS
中的窗口重定向:window.navigate("http://www.sina.com.cn";);
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)setTimeout
84.JS
中的模态显示在IE4 ,NN中不行:showModalDialog("URL"[,arguments][,features]);
85.JS
中的退出之前使用的句柄:
function verifyClose(){event.returnValue="we really like you and hope you will stay longer.";}} window.=verifyClose;
86.
当窗体第一次使用的文件句柄:onload()
87.
当窗体关闭时调用的文件句柄:onunload()
88.window.location
的属性:
protocol(http:),hostname(www.example.com),port(80),host(www.example.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

 

教程:JavaScript这么回事1-5 

有些候你精通一门语言,但是会发现你其整天在和其它言打交道,也你以为这些微不足道,不至于影响你的开发进度,但恰恰是些你不重西会浪你很多时间,我一直以我早在几年前就已精通JavaScript了,直到目前,我才越来越JavaScript比我想象的复杂大,我始崇拜它,就像崇拜所有OOP言一
趁着日的空隙,把有JavaScript的方法和技巧整理下,让每个在JavaScript烦恼的人明白,JavaScript这么回事!并希望JavaScript可以成你的朋友,你豁然朗,在目中更好的用~

适合阅读JavaScript一无所知~离精通只差一之遥的人
HTML


JavaScript
这么回事1:基

1
建脚本

1: <script language=”JavaScript”>
2: JavaScript code goes here
3: </script>



2
藏脚本代

1: <script language=”JavaScript”>
2: <!--
3: document.write(“Hello”);
4: // -->
5: </script>


在不支持JavaScript浏览器中将不行相

3
浏览器不支持的

1: <noscript>
2: Hello to the non-JavaScript browser.
3: </noscript>



4
接外部脚本文件

1: <script language=”JavaScript” src="/”filename.js"”></script>


5
脚本

1: // This is a comment
2: document.write(“Hello”); // This is a comment
3: /*
4: All of this
5: is a comment
6: */



6
出到浏览

1: document.write(“<strong>Hello</strong>”);



7
义变

1: var myVariable = “some value”;



8
字符串相加

1: var myString = “String1” + “String2”;



9
字符串搜索

1: <script language=”JavaScript”>
2: <!--
3: var myVariable = “Hello there”;
4: var therePlace = myVariable.search(“there”);
5: document.write(therePlace);
6: // -->
7: </script>



10
字符串替

1: thisVar.replace(“Monday”,”Friday”);


11
格式化字串

1: <script language=”JavaScript”>
2: <!--
3: var myVariable = “Hello there”;
4: document.write(myVariable.big() + “<br>”);
5: document.write(myVariable.blink() + “<br>”);
6: document.write(myVariable.bold() + “<br>”);
7: document.write(myVariable.fixed() + “<br>”);
8: document.write(myVariable.fontcolor(“red”) + “<br>”);
9: document.write(myVariable.fontsize(“18pt”) + “<br>”);
10: document.write(myVariable.italics() + “<br>”);
11: document.write(myVariable.small() + “<br>”);
12: document.write(myVariable.strike() + “<br>”);
13: document.write(myVariable.sub() + “<br>”);
14: document.write(myVariable.sup() + “<br>”);
15: document.write(myVariable.toLowerCase() + “<br>”);
16: document.write(myVariable.toUpperCase() + “<br>”);
17:
18: var firstString = “My String”;
19: var finalString = firstString.bold().toLowerCase().fontcolor(“red”);
20: // -->
21: </script>



12
建数

1: <script language=”JavaScript”>
2: <!--
3: var myArray = new Array(5);
4: myArray[0] = “First Entry”;
5: myArray[1] = “Second Entry”;
6: myArray[2] = “Third Entry”;
7: myArray[3] = “Fourth Entry”;
8: myArray[4] = “Fifth Entry”;
9: var anotherArray = new Array(“First Entry”,”Second Entry”,”Third Entry”,”Fourth Entry”,”Fifth Entry”);
10: // -->
11: </script>



13
排序

1: <script language=”JavaScript”>
2: <!--
3: var myArray = new Array(5);
4: myArray[0] = “z”;
5: myArray[1] = “c”;
6: myArray[2] = “d”;
7: myArray[3] = “a”;
8: myArray[4] = “q”;
9: document.write(myArray.sort());
10: // -->
11: </script>



14
分割字符串

1: <script language=”JavaScript”>
2: <!--
3: var myVariable = “a,b,c,d”;
4: var stringArray = myVariable.split(“,”);
5: document.write(stringArray[0]);
6: document.write(stringArray[1]);
7: document.write(stringArray[2]);
8: document.write(stringArray[3]);
9: // -->
10: </script>



15
出警告信息

1: <script language=”JavaScript”>
2: <!--
3: window.alert(“Hello”);
4: // -->
5: </script>



16
出确

1: <script language=”JavaScript”>
2: <!--
3: var result = window.confirm(“Click OK to continue”);
4: // -->
5: </script>



17
函数

1: <script language=”JavaScript”>
2: <!--
3: function multiple(number1,number2) {
4: var result = number1 * number2;
5: return result;
6: }
7: // -->
8: </script>



18
JS函数

1: <a href=”#” onClick=”functionName()”>Link text</a>
2: <a href="/”javascript:functionName"()”>Link text</a>



19
面加完成后行函数

1: <body onLoad=”functionName();”>
2: Body of the page
3: </body>


20
条件判断

1: <script>
2: <!--
3: var userChoice = window.confirm(“Choose OK or Cancel”);
4: var result = (userChoice == true) ? “OK” : “Cancel”;
5: document.write(result);
6: // -->
7: </script>



21
指定次数循

1: <script>
2: <!--
3: var myArray = new Array(3);
4: myArray[0] = “Item 0”;
5: myArray[1] = “Item 1”;
6: myArray[2] = “Item 2”;
7: for (i = 0; i < myArray.length; i++) {
8: document.write(myArray[i] + “<br>”);
9: }
10: // -->
11: </script>



22
定将来

1: <script>
2: <!--
3: function hello() {
4: window.alert(“Hello”);
5: }
6: window.setTimeout(“hello()”,5000);
7: // -->
8: </script>



23
时执行函数

1: <script>
2: <!--
3: function hello() {
4: window.alert(“Hello”);
5: window.setTimeout(“hello()”,5000);
6: }
7: window.setTimeout(“hello()”,5000);
8: // -->
9: </script>



24
取消定时执

1: <script>
2: <!--
3: function hello() {
4: window.alert(“Hello”);
5: }
6: var myTimeout = window.setTimeout(“hello()”,5000);
7: window.clearTimeout(myTimeout);
8: // -->
9: </script>



25
面卸载时行函数

1: <body onUnload=”functionName();”>
2: Body of the page
3: </body>

JavaScript
这么回事2浏览


26
访问document

1: <script language=”JavaScript”>
2: var myURL = document.URL;
3: window.alert(myURL);
4: </script>



27
动态输HTML

1: <script language=”JavaScript”>
2: document.write(“<p>Here’s some information about this document:</p>”);
3: document.write(“<ul>”);
4: document.write(“<li>Referring Document: “ + document.referrer + “</li>”);
5: document.write(“<li>Domain: “ + document.domain + “</li>”);
6: document.write(“<li>URL: “ + document.URL + “</li>”);
7: document.write(“</ul>”);
8: </script>


28


1: document.writeln(“<strong>a</strong>”);
2: document.writeln(“b”);



29
出日期

1: <script language=”JavaScript”>
2: var thisDate = new Date();
3: document.write(thisDate.toString());
4: </script>



30
指定日期的

1: <script language=”JavaScript”>
2: var myOffset = -2;
3: var currentDate = new Date();
4: var userOffset = currentDate.getTimezoneOffset()/60;
5: var timeZoneDifference = userOffset - myOffset;
6: currentDate.setHours(currentDate.getHours() + timeZoneDifference);
7: document.write(“The time and date in Central Europe is: “ + currentDate.toLocaleString());
8: </script>


31
置日期出格式

1: <script language=”JavaScript”>
2: var thisDate = new Date();
3: var thisTimeString = thisDate.getHours() + “:” + thisDate.getMinutes();
4: var thisDateString = thisDate.getFullYear() + “/” + thisDate.getMonth() + “/” + thisDate.getDate();
5: document.write(thisTimeString + “ on “ + thisDateString);
6: </script>


32
URL参数

1: <script language=”JavaScript”>
2: var urlParts = document.URL.split(“?”);
3: var parameterParts = urlParts[1].split(“&”);
4: for (i = 0; i < parameterParts.length; i++) {
5: var pairParts = parameterParts[i].split(“=”);
6: var pairName = pairParts[0];
7: var pairValue = pairParts[1];
8: document.write(pairName + “
“ +pairValue );
9: }
10: </script>

HTML是无状

33
一个新的document

1: <script language=”JavaScript”>
2: function newDocument() {
3: document.open();
4: document.write(“<p>This is a New Document.</p>”);
5: document.close();
6: }
7: </script>



34
面跳

1: <script language=”JavaScript”>
2: window.location = “http://www.velee.cn”;
3: </script>



35
添加网载进度窗口

1: <html>
2: <head>
3: <script language='javaScript'>
4: var placeHolder = window.open('holder.html','placeholder','width=200,height=200');
5: </script>
6: <title>The Main Page</title>
7: </head>
8: <body onLoad='placeHolder.close()'>
9: <p>This is the main page</p>
10: </body>
11: </html>



JavaScript
这么回事3



36
像属性

1: <img src="/”image1.jpg"” name=”myImage”>
2: <a href=”# ” onClick=”window.alert(document.myImage.width)”>Width</a>
3:


37
动态载图

1: <script language=”JavaScript”>
2: myImage = new Image;
3: myImage.src = “Tellers1.jpg”;
4: </script>


38
简单像替

1: <script language=”JavaScript”>
2: rollImage = new Image;
3: rollImage.src = “rollImage1.jpg”;
4: defaultImage = new Image;
5: defaultImage.src = “image1.jpg”;
6: </script>
7: <a href="/”myUrl"” onMouseOver=”document.myImage.src = rollImage.src;”
8: onMouseOut=”document.myImage.src = defaultImage.src;”>
9: <img src="/”image1.jpg"” name=”myImage” width=100 height=100 border=0>


39
随机

1: <script language=”JavaScript”>
2: var imageList = new Array;
3: imageList[0] = “image1.jpg”;
4: imageList[1] = “image2.jpg”;
5: imageList[2] = “image3.jpg”;
6: imageList[3] = “image4.jpg”;
7: var imageChoice = Math.floor(Math.random() * imageList.length);
8: document.write(‘<img src=”’ + imageList[imageChoice] + ‘“>’);
9: </script>
40
函数实现像替
1: <script language=”JavaScript”>
2: var source = 0;
3: var replacement = 1;
4: function createRollOver(originalImage,replacementImage) {
5: var imageArray = new Array;
6: imageArray[source] = new Image;
7: imageArray[source].src = originalImage;
8: imageArray[replacement] = new Image;
9: imageArray[replacement].src = replacementImage;
10: return imageArray;
11: }
12: var rollImage1 = createRollOver(“image1.jpg”,”rollImage1.jpg”);
13: </script>
14: <a href=”#” onMouseOver=”document.myImage1.src = rollImage1[replacement].src;”
15: onMouseOut=”document.myImage1.src = rollImage1[source].src;”>
16: <img src="/”image1.jpg"” width=100 name=”myImage1” border=0>
17: </a>


41
建幻灯片

1: <script language=”JavaScript”>
2: var imageList = new Array;
3: imageList[0] = new Image;
4: imageList[0].src = “image1.jpg”;
5: imageList[1] = new Image;
6: imageList[1].src = “image2.jpg”;
7: imageList[2] = new Image;
8: imageList[2].src = “image3.jpg”;
9: imageList[3] = new Image;
10: imageList[3].src = “image4.jpg”;
11: function slideShow(imageNumber) {
12: document.slideShow.src = imageList[imageNumber].src;
13: imageNumber += 1;
14: if (imageNumber < imageList.length) {
15: window.setTimeout(“slideShow(“ + imageNumber + “)”,3000);
16: }
17: }
18: </script>
19: </head>
20: <body onLoad=”slideShow(0)”>
21: <img src="/”image1.jpg"” width=100 name=”slideShow”>


42
随机广告

1: <script language=”JavaScript”>
2: var imageList = new Array;
3: imageList[0] = “image1.jpg”;
4: imageList[1] = “image2.jpg”;
5: imageList[2] = “image3.jpg”;
6: imageList[3] = “image4.jpg”;
7: var urlList = new Array;
8: urlList[0] = “http://some.host/”;
9: urlList[1] = “http://another.host/”;
10: urlList[2] = “http://somewhere.else/”;
11: urlList[3] = “http://right.here/”;
12: var imageChoice = Math.floor(Math.random() * imageList.length);
13: document.write(‘<a href=”’ + urlList[imageChoice] + ‘“><img src=”’ + imageList[imageChoice] + ‘“></a>’);
14: </script>

JavaScript
这么回事4:表


是先继续写完JS这么回事系列吧~
43
构成

1: <form method=”post” action=”target.html” name=”thisForm”>
2: <input type=”text” name=”myText”>
3: <select name=”mySelect”>
4: <option value=”1”>First Choice</option>
5: <option value=”2”>Second Choice</option>
6: </select>
7: <br>
8: <input type=”submit” value=”Submit Me”>
9: </form>


44
访问中的文本框内容

1: <form name=”myForm”>
2: <input type=”text” name=”myText”>
3: </form>
4: <a href='#' onClick='window.alert(document.myForm.myText.value);'>Check Text Field</a>


45
动态复制文本框内容

1: <form name=”myForm”>
2: Enter some Text: <input type=”text” name=”myText”><br>
3: Copy Text: <input type=”text” name=”copyText”>
4: </form>
5: <a href=”#” onClick=”document.myForm.copyText.value =
6: document.myForm.myText.value;”>Copy Text Field</a>


46
侦测文本框的

1: <form name=”myForm”>
2: Enter some Text: <input type=”text” name=”myText” onChange=”alert(this.value);”>
3: </form>


47
访问选中的Select

1: <form name=”myForm”>
2: <select name=”mySelect”>
3: <option value=”First Choice”>1</option>
4: <option value=”Second Choice”>2</option>
5: <option value=”Third Choice”>3</option>
6: </select>
7: </form>
8: <a href='#' onClick='alert(document.myForm.mySelect.value);'>Check Selection List</a>


48
动态增加Select

1: <form name=”myForm”>
2: <select name=”mySelect”>
3: <option value=”First Choice”>1</option>
4: <option value=”Second Choice”>2</option>
5: </select>
6: </form>
7: <script language=”JavaScript”>
8: document.myForm.mySelect.length++;
9: document.myForm.mySelect.options[document.myForm.mySelect.length - 1].text = “3”;
10: document.myForm.mySelect.options[document.myForm.mySelect.length - 1].value = “Third Choice”;
11: </script>


49
验证字段

1: <script language=”JavaScript”>
2: function checkField(field) {
3: if (field.value == “”) {
4: window.alert(“You must enter a value in the field”);
5: field.focus();
6: }
7: }
8: </script>
9: <form name=”myForm” action=”target.html”>
10: Text Field: <input type=”text” name=”myField”onBlur=”checkField(this)”>
11: <br><input type=”submit”>
12: </form>


50
验证Select

1: function checkList(selection) {
2: if (selection.length == 0) {
3: window.alert(“You must make a selection from the list.”);
4: return false;
5: }
6: return true;
7: }


51
动态action

1: <form name=”myForm” action=”login.html”>
2: Username: <input type=”text” name=”username”><br>
3: Password: <input type=”password” name=”password”><br>
4: <input type=”button” value=”Login” onClick=”this.form.submit();”>
5: <input type=”button” value=”Register” onClick=”this.form.action = ‘register.html’; this.form.submit();”>
6: <input type=”button” value=”Retrieve Password” onClick=”this.form.action = ‘password.html’; this.form.submit();”>
7: </form>


52
使用像按

1: <form name=”myForm” action=”login.html”>
2: Username: <input type=”text” name=”username”><br>
3: Password: <input type=”password”name=”password”><br>
4: <input type=”image” src="/”login.gif"” value=”Login”>
5: </form>
6:


53
数据的加密

1: <SCRIPT LANGUAGE='JavaScript'>
2: <!--
3: function encrypt(item) {
4: var newItem = '';
5: for (i=0; i < item.length; i++) {
6: newItem += item.charCodeAt(i) + '.';
7: }
8: return newItem;
9: }
10: function encryptForm(myForm) {
11: for (i=0; i < myForm.elements.length; i++) {
12: myForm.elements[i].value = encrypt(myForm.elements[i].value);
13: }
14: }
15:
16: //-->
17: </SCRIPT>
18: <form name='myForm' onSubmit='encryptForm(this); window.alert(this.myField.value);'>
19: Enter Some Text: <input type=text name=myField><input type=submit>
20: </form>




JavaScript
这么回事5:窗口和框架


54
变浏览器状态栏文字提示

1: <script language=”JavaScript”>
2: window.status = “A new status message”;
3: </script>


55
出确提示框

1: <script language=”JavaScript”>
2: var userChoice = window.confirm(“Click OK or Cancel”);
3: if (userChoice) {
4: document.write(“You chose OK”);
5: } else {
6: document.write(“You chose Cancel”);
7: }
8: </script>


56
提示

1: <script language=”JavaScript”>
2: var userName = window.prompt(“Please Enter Your Name”,”Enter Your Name Here”);
3: document.write(“Your Name is “ + userName);
4: </script>


57
一个新窗口

1: //
一个名称myNewWindow浏览器新窗口
2: <script language=”JavaScript”>
3: window.open(“http://www.velee.cn”,”myNewWindow”);
4: </script>


58
置新窗口的大小

1: <script language=”JavaScript”>
2: window.open(“http://www.velee.cn”,”myNewWindow”,'height=300,width=300');
3: </script>


59
置新窗口的位置

1: <script language=”JavaScript”>
2: window.open(“http://www.velee.cn”,”myNewWindow”,'height=300,width=300,left=200,screenX=200,top=100,screenY=100');
3: </script>


60
是否示工具滚动栏

1: <script language=”JavaScript”>
2: window.open(“http:


61
是否可以放新窗口的大小

1: <script language=”JavaScript”>
2: window.open('http://www.velee.cn' , 'myNewWindow', 'resizable=yes' );</script>


62
一个新的文档到当前窗口

1: <a href='#' onClick='document.location = '125a.html';' >Open New Document</a>


63
面的滚动位置

1: <script language=”JavaScript”>
2: if (document.all) { //
如果是IE浏览使用scrollTop属性
3: document.body.scrollTop = 200;
4: } else { //
如果是NetScape浏览使用pageYOffset属性
5: window.pageYOffset = 200;
6: }</script>


64
IE中打全屏窗口

1: <a href='#' onClick=”window.open('http://www.juxta.com/','newWindow','fullScreen=yes');”>Open a full-screen window</a>


65
新窗口和父窗口的操作

1: <script language=”JavaScript”>
2: //
新窗口
3: var newWindow = window.open(“128a.html”,”newWindow”);
4: newWindow.close(); //
在父窗口中关闭的新窗口
5: </script>
6:
在新窗口中关闭父窗口
7: window.opener.close()


66
往新窗口中写内容

1: <script language=”JavaScript”>
2: var newWindow = window.open(“”,”newWindow”);
3: newWindow.document.open();
4: newWindow.document.write(“This is a new window”);
5: newWIndow.document.close();
6: </script>


67
载页面到框架

1: <frameset cols=”50%,*”>
2: <frame name=”frame1” src="/”135a.html"”>
3: <frame name=”frame2” src="/”about:blank"”>
4: </frameset>
5:
frame1中加frame2中的
6: parent.frame2.document.location = “135b.html”;


68
在框架面之共享脚本
如果在frame1html文件中有个脚本

1: function doAlert() {
2: window.alert(“Frame 1 is loaded”);
3: }

frame2中可以如此方法

1: <body onLoad=”parent.frame1.doAlert();”>
2: This is frame 2.
3: </body>


69
数据公用
可以在框架面定数据,使得数据可以被多个框架中的面公用

1: <script language=”JavaScript”>
2: var persistentVariable = “This is a persistent value”;
3: </script>
4: <frameset cols=”50%,*”>
5: <frame name=”frame1” src="/”138a.html"”>
6: <frame name=”frame2” src="/”138b.html"”>
7: </frameset>


这样frame1frame2中都可以使用persistentVariable
70
框架代码库
根据以上的一些思路,我可以使用一个藏的框架面来作整个框架集的代码库

1: <frameset cols=”0,50%,*”>
2: <frame name=”codeFrame” src="/”140code.html"”>
3: <frame name=”frame1” src="/”140a.html"”>
4: <frame name=”frame2” src="/”140b.html"”>
5: </frameset>

 

教程:事半功倍系列之javascript From:IT博客 
本文由论坛 永炎 整理

大学出版的《事半功倍系列 javascript,本人照着敲出来的,有些翻了一下.前几年看了一下,最近无事,重新翻了翻,很有帮助.书应该有光,但学校的,不知在哪.希望你学 javascript有帮助

第一章javascript

1.
在地址栏输javascript

Javascript:Document.write("
示文字")

2.
javascript嵌入 HTML文档

<script language=javascript>
document.bgColor="blue"
</script>

第二章 使用量和数

1.
声明

<script language=javascripe>
Var answer1,answer2,answer3,answer4;
answer1=9;
answer2=2.5
answer3="Milkey May"
answer4=true
</script>

2.
使用整数

<script language=javascript>
var decimalNum,hexadecimalNum,octalNum
decimalNum=24
hexadecimalNum=0x24
octalNum=024
document.write("
示十制数:"+ decimalNum+"<br>")
document.write("
示十六制数:"+ hexadecimalNum +"<br>")
document.write("
示八制数:"+ octalNum +"<br>")
</script>

3.
使用浮点数

<script language=javascript>
var num1,num2,num3,num4
num1=1234567890000.0
num2=5.14e23
num3=0.0000123456
num4=6.0254e3-4
document.write("
浮点数1"+num1+"<br>")
document.write("
浮点数2"+num2+"<br>")
document.write("
浮点数3"+num3+"<br>")
document.write("
浮点数4"+num4+"<br>")
</script>

4.
使用布尔值

<script language=javascript>
var answer1,answer2
answer1=true
answer2=false
document.write("
示布1"+answer1+"<br>")
document.write("
示布2"+answer2+"<br>")
</script>

5.
使用字符串

<script language=javascript>
var str1,str2
str1="fdsgdg dsfdsf china"
str2="
市广播电视大学"
document.write("
示字符串1"+str1+"<br>")
document.write("
示字符串2"+str2+"<br>")
</script>

6.
确定

<script>
var answer1,answer2,answer3,answer4
answer1=9
answer2=2.5
answer3="milky may"
answer4=true
document.write("
1型是:"+typeof answer1 +"<br>")
document.write("
2型是:"+typeof answer2 +"<br>")
document.write("
3型是:"+typeof answer3 +"<br>")
document.write("
4型是:"+typeof answer4 +"<br>")
</script>

7.
将字符串转换成数字

<script>
var str1="31 days in january"
var int1=parseInt(str1)
document.write("str1
的数据型是 "+typeof str1+"<br>")
document.write("int1
的数据型是 "+typeof int1+"<br>")
</script>

8.
将数字转换成字符串

<script>
var int1=256
var str1=""+int1
document.write("str1
的数据型是 "+typeof str1+"<br>")
document.write("int1
的数据型是 "+typeof int1+"<br>")
</script>

9.
声明数

<script>
array=new Array(5)
array[0]=1
array[1]=3
array[2]=5
array[3]=7
array[4]=11
document.write("
是:"+array[0]+" "+array[1]+" "+array[2]+" "+array[3]+" "+array[4])
</script>

10.
确定数元素的个数

<script>
array=new Array(5)
array[0]=1
array[1]=3
array[2]=5
array[3]=7
array[4]=11
document.write("
是:"+array[0]+" "+array[1]+" "+array[2]+" "+array[3]+" "+array[4]+"<br>")
document.write("
的元素个数是"+array.length)
</script>

11.
将数组转换为字符串

<script>
array=new Array()
array[0]="dark"
array[1]="apple"
array[2]="nebula"
array[3]="water"
str1=array.join()
str2=array.join(" ")
document.write(str1+"<br>")
document.write(str2)
</script>

12.
排序

<script>
array=new Array()
array[0]="dark"
array[1]="apple"
array[2]="nebula"
array[3]="water"
str1=array.sort()
document.write(str1+"<br>")
</script>

第三章 建表达式

1.
使用算运算符

<script>
var1=12
var2=10
varadd=var1+var2
varsub=var1-var2
varmult=var1*var2
vardiv=var1/var2
varmod=var1%var2
document.write("
数据1是:"+var1+"<br>")
document.write("
数据2是:"+var2+"<br>")
document.write("
数据相加是:"+varadd+"<br>")
document.write("
数据相减是:"+varsub+"<br>")
document.write("
数据相乘是:"+varmult+"<br>")
document.write("
数据相除是:"+vardiv+"<br>")
document.write("
数据相除取余数是:"+varmod+"<br>")
</script>

2.
量和

<script>
days=1
document.write("
"+days+"<br>")
days++
document.write("
增后变为"+days)
</script>

3.
建比表达式

<script>
daysofmonth=28
if(daysofmonth==28)
month="february"
document.write("days of month:"+daysofmonth+"<br>")
document.write("month:"+month)
</script>

4.
逻辑表达式

<script>
dayofmonth=28
if(dayofmonth==28 || dayofmonth==29)
month="february"
document.write("days of month:"+dayofmonth+"<br>")
document.write("month:"+month)
</script>

5.
使用条件运算符

<script language="javascript">
stomach="hungry";
time="5:00";
(stomach=="hungry"&&time=="5:00") ? eat = "dinner":eat="a snack";
document.write("
"+eat);
</script>

6.
识别数字

<script>
var1=24;
(isNaN(var1))?document.write("
var1"+var1+"不是数字"):Document.write("var1"+var1+"是数字")
</script>

第四章 控制程序流程

1.
使用IF –Else

<script>
month="december"
date=25
if(month=="december" && date==25)
document.write("
今天是圣诞节,商店关门")
else
document.write("
,您来商店")
</script>

2.
使用for

<script>
for (count=1;count<=10;count++)
document.write("
出第"+count+""+"<br>")
</script>

3.
使用while

<script>
count=1
while(count<=15){
document.write("
出第"+count+"" +"<br>")
count++}
</script>

4.
中断循

<script>
count=1
while(count<=15){
count++
if(count==8)
break;
document.write("
出第"+count+""+"<br>")}
</script>

5.
继续

<script>
count=1
while(count<=15){
count++
if(count==8)
continue;
document.write("
出第"+count+""+"<br>")}
</script>

6.
使用javascript

<script>
function rabbit()
{document.write("
")
}
</script>
<body onload=window.setTimeout(rabbit(),5000)>

7.
置定期

<script>
window.setInterval("document.form1.text2.value=document.form1.text1.value",3000)
</script>
<form name=form1>
<input type=text name=text1><br>
<input type=text name=text2><br>
</form>

8.
清除超

<script>
stop=window.setInterval("document.form1.text2.value=document.form1.text1.value",300)
</script>
<form name=form1>
<input type=text name=text1><br>
<input type=text name=text2><br>
<input type=button name=button1 value="
清除超" onclick=clearInterval(stop)>
</form>

第五章 使用函数

1.
声明函数

<script>
function quote()
{ document.write("
")
}
</script>

2.
用函数

<script>
function quote()
{ document.write("
")
}
quote()
</script>

3.
了解全局量和局部

任何不用 var关键字声明的量都是全局,任何在函数外声明的量都是全局

4.
将参数函数

<script>
function f(item)
{document.write("
出参数"+item+"<br>")
}
f("fgdfgd")
f("
参数二")
</script>

5.
从函数返回

<script>
function average(var1,var2,var3)
{ave=(var1+var2+var3)/3;
document.write("
");
return ave;
}
document.write(average(34,56,78))
</script>

6.
HTML用函数

<script>
function quote(){
document.write("
出字符串")
}
</script>
<a href=javascript:quote()>
HTML用函数</a>
<a href=javascript:Document.write("
出字符")> HTML用函数,直接写javascript</a>

第六章 理事件

1.
检查标单击

<form name=form1>
<input type=button name=button1 value=hello onclick=document.form1.button1.value='there'>
</form>

2.
检测

<form name=form1>
<input type=button name=button1 value=hello onclick=document.form1.button1.value='
单击了按' ondblclick=document.form1.button1.value='你双'>
</form>

3.
停按

<img src=go.gif onmouseover=document.images[0].src='go2.gif' onmouseout= document.images[0].src='go.gif'>

4.
检测

<form name=form1>
<input type=text name=text1 value=hello onkeypress="if(window.event.keyCode=='100') document.form1.text1.value='
你按了d'">
</form>

5.
置焦点

<form name=form1>
<input type=text name=text1 value=hello
onfous=document.form1.text1.value='
文本框得焦点'
onblur=document.form1.text1.value='
文本框失去焦点'>
</form>

6.
检测下拉菜单选择

<form name=form1>
<select name=select1 size=4
onChange=document.form1.text1.value=document.form1.select1.value>
<option value="
北京">北京</option>
<option value="
上海">上海</option>
<option value="
"></option>
<option value="
天津">天津</option>
<option value="
"></option>
</select>
<input tppe=text name=text1 value=hello>
</form>

7.
建网和卸信息

<body onload=document.form1.text1.value='
面加' onunload=alert(',迎再来')>
<form name=form1>
<input type=text name=text1 value="
面正在加 ……">
</form>

第七章 使用

1.
理解\属性和方法

<body bgcolor="green">
<script>
document.write("
面背景色是:"+document.bgColor)
document.write("
面前景色是:"+document.fgColor)
</script>

2.
使用网元素

<script>
</script>
<form name=form1>
<textarea name=ta1>dfgfdgfdhfdhdfdfgdf</textarea>
<input type=button value="
选择文本" onclick=document.form1.ta1.select()>
<input type=button value="
示文本" onclick=document.write(document.form1.ta1.value)>
</form>

3.
使用子


<form name=form1>
<input type=text name=text1 value=hello>
</form>
<script>
document.form1.text1.value="gdfgfd"
</script>

<form name=form1>
<input type=radio name=radio1>

<input type=radio name=radio2>

</script>
<script>
document.form1.radio1.checked=true
</script>

4.
使用义对

<script>
str1="dgdfgdfgdfhf
固定法固定法功夫攻打法"
document.write(str1+"<br>")
str2=str1.substr(5)
document.write(str2+"<br>")
document.write("
的面:"+Math.PI*Math.pow(5.0,2))
</script>

5.
建新

<script>
today=new Date()
document.write("
今天是"+(today.getMonth()+1)+""+today.getDate()+""+"<br>")
document.write("
在是:"+today.toLocaleString())
</script>

6.
引用当前

<form name=form1>
<input type=text name=text1 value="dgdgdfgfd" onclick=this.select()>
</script>

7.
象属性

<script>
for(prop in window)
{document.write("window."+prop+"="+window[prop]+"<br>");}
for(prop2 in location)
{document.write("location."+prop2+"="+location[prop]+"<br>");}
</script>

8.
使用Array

<script>
array=new Array(10)
array[0]="bark"
array[1]="apple"
array[2]="nebula"
array[3]="cookie"
array[4]="technology"
document.write("
元素个数是"+array.Length+"<br>")
document.write("
join将数合并"+array.join(" ")+"<br>")
document.write("
排序"+array.sort())
</script>

9.
使用 image

<img src=**.gif alt="
片提示…." border=10>
<script>
document.write("
片提示是:"+document.images[0].alt+"<br>")
document.write("
框大小是:"+document.images[0].broder)
</script>

10.
载图

<script>
freddy=new Image()
freddy.src=freddy.gif
</script>
<body onload=document.images[0].src=freddy.src>
,<img src="blank.gif">
</body>

11.
变图

<img src=freddy.gif><br>
<form name=form1>
<input type=button name=button1 value="
变图" onclickd=document.images[0].src=dudjp.gif>
</form>

12.
使用linkanchor

<a name=anchor1>
1<br>
<a href=http://www.microsoft.com>Microsoft</a><br>
<a href=http://www.sohu.com>sohu</a><br>
<a href=http://www.sina.com.cn>sina</a><br>
<script>
document.write("
面共有"+document.links.length+""+"<br>")
document.write("
面共有"+document.anchors.length+""+"<br>")
document.write("
第一个协议"+document.links[0].protocol+"<br>")
document.write("
第一个接路径是"+document.links[0].pathnamel+"<br>")
document.write("
第一个href"+document.links[0].hrefl+"<br>")
</script>

13.
变链

<a href =http://www.microsoft.com>link</a>
<form name=form1>
<input type=button name=button1 value="
变链" onclick=document.links[0].href='http://www.sohu.com'>
</form>

14.
使用history

<form name=form1>
<input type=button name=button1 value="
向后返回2" onclick=window.history.go(-2)>
</form>

第八章 使用窗口

1.
浏览器的状态栏示文本

<body onload=window.status="
迎光我的站点">
<a href=http://www.sohu.com>sohu</a>
</body>

2.
背景色

<script>
document.bgColor="orange"
</script>

3.
背景

<body bgColor =green>
<script>
document.write("
当前背景色是:"+document.bgColor)
</script>
</body>

4.
文本和

<script>
document.bgColor="orange"
document.fgColor="blue"
document.linkColor="red"
</script>
<h2>
看看段文本</h2>
<a href=http://www.sohu.com>sohu</a>
</body>

5.
文档标题

<script>
name="Mouse"
document.title="welcome to "+name+"'s House"
document.write(document.title)
</script>

6.
示修改日期

<script>
document.write("
面最后修改时间"+document.lastModified)
</script>

7.
看当前文档的URL

<script>
document.write("
面的URL:"+document.URL)
</script>

8.
看引用

<script>
document.write("
面的引用"+document.referrer)
</script>

9.
新的浏览器窗口

<script>
window.open("*.htm","title","width=200,height=400,resizable=yes")
</script>

10.
关闭远程窗口


close.html:
<script>
document.write("
正文")
</script>
<form name=form1>
<input type=button name=button1value="
关闭" onclick=window.close()>
</form>

open.html
<script>
window.open("close.html","romote","width=200,height=400,resizable=yes")
</script>

11.
打印窗口

<script>
document.write("
正文")
</script>
<form name=form1>
<input type=button value=
打印 onclick=window.print()>
</form>

12.
窗口


<form name=form1>
水平方向<input type=text name=x value=20>
垂直方向<input type=text name=y value=50>
<input type=button value="
窗口到…"onclick=window.moveTo(document.form1.x.value,document.form1.y.value)>
</form>

<form name=form1>
水平方向<input type=text name=x value=20>
垂直方向<input type=text name=y value=50>
<input type=button value="
窗口"onclick=window.moveBy(document.form1.x.value,document.form1.y.value)>
</form>


13.
窗口大小


<form name=form1>
水平方向<input type=text name=x value=200>
垂直方向<input type=text name=y value=500>
<input type=button value="
窗口大小到….."onclick=window.resizeTo(document.form1.x.value,document.form1.y.value)>
</form>

<form name=form1>
水平方向<input type=text name=x value=200>
垂直方向<input type=text name=y value=500>
<input type=button value="
窗口大小"onclick=window.resizeBy(document.form1.x.value,document.form1.y.value)>
</form>

14.
用警告对话框通知用

<script>
window.alert("welcome")
</script>

15.
用提示对话框接受

<script>
name=window.prompt("
入姓名","姓名")
document.write("
迎您:"+name+"来到")
</script>

16.
用确认对话框使用做出决定

<script>
like=window.confirm("
得好?")
if(like==true)
document.write("
谢谢你的夸")
else
document.write("
希望得到你的夸")
</script>

第九章 使用字符串

1.
使用字符串

<script>
mystring="gdgdfgfddddaaaaaaaaaaaabbbbbbbbbbbbbbbbbvbhg.<br>"
document.write(mystring)
document.write(mystring.bold())
document.write(mystring.toUpperCase())
</script>

2.
使用子字符串

<script>
str1="fdsf 1111 gfdgfd dfdsf cccc dddd.<br>"
document.write(str1)
document.write(str1.substring(0,13)+"<br>")
document.write(str1.substr (20,11)+"<br>")
</script>

3.
接字符串

<script>
str1="may you find"
str2="peace,happiness and prosperity.<br>"
document.write(str1+"<br>")
document.write(str2)
document.write(str1.concat(str2))
document.write(str1+=str2)
</script>

4.
格式化字符串

<script>
str1="peace,happiness and prosperity.<br>"
document.write(str1)
document.write(str1.big())
document.write(str1.small())
document.write(str1.bold())
document.write(str1.italics())
document.write(str1.strike())
document.write(str1.fontsize(6))
document.write(str1.fontcolor(green))
</script>

5.


<script>
str1="this is the bigginning of the page.<br>"
str2="….<br>"
str3="this is the end of the page .<br>"
str4="link to the start<br>"
str5="link to the end<br>"
document.write(str1.anchor("start"))
for(i=0;i<10;i++)
document.write(str2);
document.write(str3.anchor("end"))
document.write(str4.link("#start"))
document.write(str5.link("#end"))
</script>

6.
确定字符串

<script>
str1="this is the bigginning of the page."
document.write(str1+"<br>")
document.write( "
字符串的度是:"+str1.length)
document.write("
字符串全部大写是;"+str1.toUpperCase())
document.write("
字符串全部小写是;"+str1.toLowerCase())
</script>

7.
在字符串内搜索

<script>
str1="this is the end of the line.<br>"
document.write(str1)
document.write("
字符end在字符串的位置是"+str1.search("end"))
document.write("
字符dog在字符串的位置是"+str1.search("dog"))
</script>

8.
定位字符串中的字符

<script>
str1="spring is a time for flowers and trees and baby bunnles<br>"
document.write(str1)
document.write("the index for the second word ‘and' is"+str1.indexOf("and",30))
documednt.write("the last index of the word ‘and' is "+str1.lastIndexOf("and"))
</script>

9.
字符串中的文本

<script>
str1="spring is a time for flowers and trees and baby bunnles<br>"
document.write(str1)
document .write(str1.replace("and",","))
</script>

10.
字符串分离

<script>
str1="spring is a time for flowers and trees and baby bunnles<br>"
document.write(str1)
str1array=str1.split(" ")
document.write(str1array[0]+"<br>")
document.write(str1array[1]+"<br>")
document.write(str1array[2]+"<br>")
document.write(str1array[3]+"<br>")
</script>

第十章 使用日期和时间

1.
使用Date

<script>
cdate=new Date("august 2,1989 12:30:00")
document.write(cdate)
</script>

2.
示当地时间和日期

<script>
cdate=new Date()
document.write("
当前时间:"+cdate.toGMTString()+"<br>")
document.write("
日期和时间:"+cdate.toLocaleString())
</script>

3.
时间和日期

<script>
cdate=new Date()
document.write("
示当前的星期"+cdate.getDay()+"<br>")
document.write("
示当前的月份"+cdate.getMonth()+"<br>")
document.write("
示当前的日期"+cdate.getDay()+"<br>")
document.write("
示当前的年份"+cdate.getYear()+"<br>")
document.write("
示当前的小"+cdate.getHours()+"<br>")
document.write("
示当前的分"+cdate.getMinutes()+"<br>")
document.write("
示当前的秒"+cdate.getSeconds()+"<br>")
</script>

4.
时间和日期

<script language=javascript>
cdate=new Date("December 25,1984")
document.write("
示日期"+cdate+"<br>")
document.write("
置月份"+cdate.setMonth(10)+"<br>")
document.write("
置日期"+cdate.setDate(23)+"<br>")
document.write("
置年份"+cdate.setYear(2000)+"<br>")
document.write("
置小"+cdate.setHours(13)+"<br>");
document.write("
置分"+cdate.setMinutes(47)+"<br>");
document.write("
置秒"+cdate.setSeconds(23)+"<br>");
document.write("
置后的日期和时间"+cdate);
</script>

第十一章 使用Math

1.
使用Math

<script language=javascript>
</script>
<form name=form1>
的半径:<input type=text name=rad><br>
的面:<input type=text name=area><br>
<input type=button name=button1 value=
的面 onclick=document.form1.area.value=document.form1.rad.value*document.
form1.rad.value*Math.PI>
</form>

2.
生成随机数

<script>
array1=new Array(
"
是第1",
"
是第2",
"
是第3",
"
是第4",
"
是第5",
"
是第6")
RandomNo=Math.floor(array1.length*Math.random())
document.write("
随机出某一句"+"<br>"+array1[RandomNo])
</script>

3.
使用平方根

<form name=form1>
value:<input type=text name=va1><br>
平方根<input type=text name=sqrt><br>
<input type=button name=button1 value=
算平方根
onclick="document.form1.sqrt.value=Math.sqrt(document.form1.va1.value)">
</form>

4.
数字的舍入

<form name=form1>
<input type=text name=val><br>
舍入的<input type=text name=round><br>
<input type=button name=button1 value=
onclick=document.form1.round.value=Math.round(document.form1.val.value)>
</form>

5.
乘方运算

<form name=form1>
底数<input type=text name=val><br>
指数<input type=text name=power><br>
<input type=text name=result><br>
<input type=button name=button1 value=
onclick="document.form1.result.value=Math.pow (document.form1.val.value,document.form1.power.value)">
</form>

6.
发现最小和最大

<form name=form1>
数字1<input type=text name=val1><br>
数字2<input type=text name=val2><br>
最小<input type=text name=min><br>
最大<input type=text name=max><br>
数字1<input type=button value= onclick="document.form1.min.value=Math.min (document.form1.val1.value,document.form1.val2.value);document.form1.
max.value= Math.max(document.form1.val1.value,document.form1.val2.value)">
</form>

第十二章 使用表

1.
使用文本框


<form name=form1>
<input type=text value="information ,please"name=text1>
</form>
<script>
document.write("
text1型是: "+document.form1.text1.type+"<br>")
document.write("
text1名称是: "+document.form1.text1.name+"<br>")
document.write("
text1: "+document.form1.text1.value+"<br>")
document.write("
text1大小是: "+document.form1.text1.size+"<br>")
</script>

<form name=form1>
<input type=text name=text1 value=click here
onfocus=document.form1.text1.select()>
</form>

2.
使用密

<form name=form1>
<input type=password name=pw1 value=daylight>
</form>
<script>
document.write("
pw1:"+document.form1.pw1.type+"<br>")
document.write("
pw1的名称:"+document.form1.pw1.name+"<br>")
document.write("
pw1:"+document.form1.pw1.value+"<br>")
document.write("
pw1的大小:"+document.form1.pw1.size+"<br>")
</script>

3.
使用藏字段

<form name=form1>
<input type=hidden name=hid1 value=piece of eight>
</form>
<script>
document.write("
hid1:"+document.form1.hid1.type+"<br>")
document.write("
hid1的名称:"+document.form1.hid1.name+"<br>")
document.write("
hid1:"+document.form1.hid1.value+"<br>")
</script>

4.
使用文本区域框


<form name=form1>
<textarea name=ta1>how many grains of sand are there in the sahara desert?</textarea>
</form>
<script>
document.write("
ta1:"+document.form1.ta1.type+"<br>")
document.write("
ta1的名称:"+document.form1.ta1.name+"<br>")
document.write("
ta1:"+document.form1.ta1.value+"<br>")
document.write("
ta1的横向:"+document.form1.ta1.cols+"<br>")
document.write("
ta1:"+document.form1.rows.value+"<br>")
</script>

6.
使用重置按

<form name=form1>
<input type=reset name=reset1 value="rest form">
</form>
<script>
document.write("
reset1:"+document.form1.reset1.type+"<br>")
document.write("
reset1的名称:"+document.form1.reset1.name+"<br>")
document.write("
reset1:"+document.form1.reset1.value+"<br>")
</script>

7.
使用提交按

<form name=form1>
<input type=submit name=submit1 value="submit form">
</form>
<script>
document.write("
submit1:"+document.form1.submit1.type+"<br>")
document.write("
submit1的名称:"+document.form1.submit1.name+"<br>")
document.write("
submit1:"+document.form1.submit1.value+"<br>")
</script>

8.
使用复选

<form name=form1>
<input type=checkbox name=cb1 >computer savvy?
</form>
<script>
document.write("
cb1:"+document.form1.cb1.type+"<br>")
document.write("
cb1是否被选择?:"+document.form1.cb1.checked+"<br>")
document.write("
cb1的名称:"+document.form1.cb1.name+"<br>")
</script>

9.
使用单选

<form name=form1>
<input type=radio name=radio1>male
<input type=radio name=radio1>female
</form>
<script>
document.write("
第一个按选择"+document.form1.radio1[0].checked+"<br>")
document.write("
第二个按选择"+document.form1.radio1[1].checked+"<br>")
document.write("
的名称"+ document.form1.radio1[0].name+"<br>")
document.write("
的个数"+document.form1.radio1.length)
</script>

10.
使用选择列表

<form name=form1>
<select name=select1 size=4>
<option name=option1 value=lon>london,England</option>
<option name=option2 value=dub>Dublin,Ireland</option>
</select>
</form>
<script>
document.write("
选择列表的名称"+document.form1.select1.name+"<br>")
document.write("
选择列表的"+document.form1.select1.length+"<br>")
document.write("
选择列表当前被选择的索引号"+document.form1.select1.selectedIndex+"<br>")
document.write("
选择列表的尺寸"+document.form1.select1.size+"<br>")
</script>

11.
验证的有效性

<script>
function validate(){
if(document.form1.text1.value!='1'||'2'||'3'||'4'){
alert("
请输1~4的整数")
}
}
</script>
<form name=form1>
请输1~4的整数:
<input type=text name=text1 size=4 onchange=validate()>
</form>

12.
控制表焦点

<form name=form1>
<input type=text name=text1 value=where is you focus?><br>
<input type=text name=text2 value=is there?><br>
<input type=text name=text3 value=or maybe here?><br>
<input type=button name=button1 value="text box #1" onclick=document.form1.text1.focus()><br>
<input type=button name=button2 value="text box #2" onclick=document.form1.text2.focus()><br>
<input type=button name=button3 value="text box #3" onclick=document.form1.text3.focus()><br>
</form>

第十三章 使用分

第十四章 使用navigator

1.
使用navigator

<script>
document.write("navigator
象的属性"+"<br>")
document.write("appcodename:"+navigator.appCodeName+"<br>")
document.write("appname::"+navigator.appName+"<br>")
document.write("appversion:"+navigator.appVersion+"<br>")
document.write("platform:"+navigator.platform+"<br>")
document.write("userAgent:"+navigator.userAgent+"<br>")
</script>
<script>
document.write("navigator
象的方法"+"<br>")
document.write("javaEnabled():"+navigator.javaEnabled())
</script>

2.
检查浏览

<script>
if(navigator.appName.indexOf("Microsoft")!=-1){
document.write("
户浏览器是微IE浏览"+"<br>")}
else if(navigator.appName.indexOf("Netscape")!=-1){
document.write("
户浏览器是netscapenetscape浏览"+"<br>")}
if(navigator.appVersion.indexOf("4.0")!=-1){
document.write("you are using a version 4.0compatible browser")
}
else{
document.write("this browser is not 4.0 compliant")}
</script>

3.
检测的操作系

<script>
if (navigator.platform.indexOf("win32")!=-1){
document.write("you are using a computer running windows 95 or highter")}
else{
document.write("this computer is not running windows 95 or higher")}
</script>

4.
使用location


<script>
document.write("location
象的属性"+"<br>")
document.write("hash"+location.hash+"<br>")
document.write("hostname"+location.hostname+"<br>")
document.write("host"+location.host+"<br>")
document.write("href"+location.href+"<br>")
document.write("port"+location.port+"<br>")
document.write("search"+location.search+"<br>")
</script>

重新加
<form name=form1>
<input type=button name=button1 value=
重新加 onclick=location.reload>
</form>


5.
使用cookie


<script>
finction makecookie(){
if(!document.cookie){
name=prompt("
请输入你的姓名");
document.cookie="name="+name+";";}
}
</script>

<body onload=makecookie()>
<script>
function makecookie(){
if(!document.cookie){
name=prompt("
请输入你的姓名")
document.cookie="name="+name+";";
namestart=document.cookie.indexOf("=");
nameend=document.cookieindexOf(";");
document.writeln("your name is:"+document.cookie.substring(namestart+1,nameend)+",br>")
}
}
</script>

posted on 2007-07-05 18:04 TRE-China R&D 阅读(484) 评论(0)  编辑 收藏 引用 所属分类: Javascript
只有注册用户登录后才能发表评论。