<div id="Layer1" style="position:absolute; width:260px; height:115px; z-index:1; left: 50px; top: 77px; filter:Alpha(opacity=30)">
</div>
不過這兩個函數還是有區別的,setInterval在執行完一次代碼之后,經過了那個固定的時間間隔,它還會自動重復執行代碼,而setTimeout只執行一次那段代碼。
</script>
/***********************/
i n Javascript:
去掉leading/trailing 空格: str = str.replace(/^\s+|\s+$/g,"");
去掉all空格: str = str.replace(/\s+/g,"");
2.getElementsByName
作用:按元素的名稱查找,返回一個同名元素的數組
語法: document.getElementsByName(name)
參數:name :必選項為字符串(String)
返回值:數組對象; 如果無符合條件的對象,則返回空數組,按在頁面中出現的次序
3.getElementsByTagName
作用:按HTML標簽名查詢,返回一個相同標簽元素的數組
語法: object.getElementsByTagName(tagname) object可以是document或event.srcElement.parentElement等
參數:tagname:必選項為字符串(String),根據HTML標簽檢索。
返回值:數組對象; 如果無符合條件的對象,則返回空數組,按在頁面中出現的次序
function Rectangle(x,y)//自己構造一個對象
{
this.width=x;
this.height=y;
this.area=rectangle_area;//*****//
}
function rectangle_area()//定義一個求矩形面積的方法
{
return this.width*this.height;
}
function testObject()
{
var r=new Rectangle(3,4);
alert(r.area());//調用面積的方法
var obj=new Object();//利用原型對象Object構造一個obj
obj.title='你好!';
alert(obj.title);
obj.people=new Object();//在Obj的基礎上在定義一個對象people
obj.people.name='王世清';
alert(obj.people.name);
obj.people2={name:'wsq',age:22};//在Obj的基礎上在定義一個對象people2,利用直接量方法
alert(obj.people2.name+obj.people2.age);
delete obj.people2.name; //刪除某個對象的屬性
alert(obj.people2.name); //name屬性刪除后此時的name值是Undefined
alert(obj.people2.age);
}
</script>
</head>
<body onload="testObject()">
</body>
</html>
// alert(value.length); 求長度
/************ Math ***************/
/*
Math.abs(- 8.09);
Math.exp( 5.7);
Math.random();
Math.sqrt(9.08);
Math.pow( 2,3); //乘方
Math.round(99.6);
alert(Math.sin(value));
alert((Math.sqrt(value))); 開平方
*/
/**************對字符串的操作****************/
// alert(value.substring(0,3)); 截取 *方法小寫*
// alert(value.charAt(2)); 截取相應的位置的字符
// alert(value.indexOf("a")); 獲取字符a的位置
//var now=new Date();
//alert(now.toLocaleString());
/*******數組********/
/*var array=new Array(1,2,3);
for(var i=0;i<3;i++)
{
alert(array[i]);
}*/
/*******三種彈出對話框************/
/*
window.alert("密碼不能為空!");
window.confirm('真的要發表?');
window.prompt("你好!","請輸入要查找的字符:");
*/
}
</script>
</head>
<body>
<input type="text" id="Text" onBlur="check(this.value)">
</body>
</html>
1)Alert box
<html>
<head>
<script type="text/javascript">
function disp_alert()
{
alert("I am an alert box!!")
}
</script>
</head>
<body>
<input type="button" onclick="disp_alert()" value="Display alert box" />
</body>
</html>
(2) confirm box
<html>
<head>
<script type="text/javascript">
function disp_confirm()
{
var r=confirm("Press a button")
if (r==true)
{
document.write("You pressed OK!")
}
else
{
document.write("You pressed Cancel!")
}
}
</script>
</head>
<body>
<input type="button" onclick="disp_confirm()" value="Display a confirm box" />
</body>
</html>
(3)
Prompt box
<html>
<head>
<script type="text/javascript">
function disp_prompt()
{
var name=prompt("Please enter your name","Harry Potter")
if (name!=null && name!="")
{
document.write("Hello " + name + "! How are you today?")
}
}
</script>
</head>
<body>
<input type="button" onclick="disp_prompt()" value="Display a prompt box" />
</body>
</html>
(4)
Call a function1
<html>
<head>
<script type="text/javascript">
function myfunction()
{
alert("HELLO")
}
</script>
</head>
<body>
<form>
<input type="button"
onclick="myfunction()"
value="Call function">
</form>
<p>By pressing the button, a function will be called. The function will alert a message.</p>
</body>
</html>
(5)
Function with an argument
<html>
<head>
<script type="text/javascript">
function myfunction(txt)
{
alert(txt)
}
</script>
</head>
<body>
<form>
<input type="button"
onclick="myfunction('Hello')"
value="Call function">
</form>
<p>By pressing the button, a function with an argument will be called. The function will alert
this argument.</p>
</body>
</html>
(7)Function with an argument 2
<html>
<head>
<script type="text/javascript">
function myfunction(txt)
{
alert(txt)
}
</script>
</head>
<body>
<form>
<input type="button"
onclick="myfunction('Good Morning!')"
value="In the Morning">
<input type="button"
onclick="myfunction('Good Evening!')"
value="In the Evening">
</form>
<p>
When you click on one of the buttons, a function will be called. The function will alert
the argument that is passed to it.
</p>
</body>
</html>
(8)
Function_return
<html>
<head>
<script type="text/javascript">
function myFunction()
{
return ("Hello, have a nice day!")
}
</script>
</head>
<body>
<script type="text/javascript">
document.write(myFunction())
</script>
<p>The script in the body section calls a function.</p>
<p>The function returns a text.</p>
</body>
</html>
(9)
<html>
<head>
<script type="text/javascript">
function product(a,b)
{
return a*b
}
</script>
</head>
<body>
<script type="text/javascript">
document.write(product(4,3))
</script>
<p>The script in the body section calls a function with two parameters (4 and 3).</p>
<p>The function will return the product of these two parameters.</p>
</body>
</html>
(10)
loop
<html>
<body>
<script type="text/javascript">
for (i = 0; i <= 5; i++)
{
document.write("The number is " + i)
document.write("<br />")
}
</script>
<p>Explanation:</p>
<p>This for loop starts with i=0.</p>
<p>As long as <b>i</b> is less than, or equal to 5, the loop will continue to run.</p>
<p><b>i</b> will increase by 1 each time the loop runs.</p>
</body>
</html>
(11)
<html>
<body>
<script type="text/javascript">
for (i = 1; i <= 6; i++)
{
document.write("<h" + i + ">This is header " + i)
document.write("</h" + i + ">")
}
</script>
</body>
</html>
(12)
<html>
<body>
<script type="text/javascript">
i = 0
while (i <= 5)
{
document.write("The number is " + i)
document.write("<br />")
i++
}
</script>
<p>Explanation:</p>
<p><b>i</b> is equal to 0.</p>
<p>While <b>i</b> is less than , or equal to, 5, the loop will continue to run.</p>
<p><b>i</b> will increase by 1 each time the loop runs.</p>
</body>
</html>
(13)
<html>
<body>
<script type="text/javascript">
i = 0
do
{
document.write("The number is " + i)
document.write("<br />")
i++
}
while (i <= 5)
</script>
<p>Explanation:</p>
<p><b>i</b> equal to 0.</p>
<p>The loop will run</p>
<p><b>i</b> will increase by 1 each time the loop runs.</p>
<p>While <b>i</b> is less than , or equal to, 5, the loop will continue to run.</p>
</body>
</html>
(14)
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=10;i++)
{
if (i==3){break}
document.write("The number is " + i)
document.write("<br />")
}
</script>
<p>Explanation: The loop will break when i=3.</p>
</body>
</html>
(15)
<html>
<head>
<script type="text/javascript">
var txt=""
function message()
{
try
{
adddlert("Welcome guest!")
}
catch(err)
{
txt="There was an error on this page.\n\n"
txt+="Error description: " + err.description + "\n\n"
txt+="Click OK to continue.\n\n"
alert(txt)
}
}
</script>
</head>
<body>
<input type="button" value="View message" onclick="message()" />
</body>
</html>
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屬性代表為是否選中返回TRUE或FALSE)
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.onbeforeunload=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
至于二級菜單的指上去變紅色的效果則純是css寫的。秘密如下:
#nav li ul a:link {
color:#666; text-decoration:none;
}
#nav li ul a:visited {
color:#666;text-decoration:none;
}
#nav li ul a:hover {
color:#F3F3F3;text-decoration:none;font-weight:normal;
background:#C00;
}
link表示一個鏈接a在頁面上顯示的樣式,visited表示鏈接訪問后的樣式,hover表示指上去后的樣式,這里的hover是IE唯一一個支持的這種寫法。還有一個虛選擇器active,表示激活后的樣式。注意,a的這四個虛選擇器是有順序的,必須按lvha這個順序寫才會有效,可以記為love與hate,喜歡和討厭,好記吧,呵呵。