1:在一帶到復(fù)雜的FRAME頁面中OPEN一個窗體來(當(dāng)然不用什么parent.parent啦)









以下的LINK來觸發(fā)



當(dāng)然下面的不能少啦!



2:關(guān)閉一當(dāng)前窗口,并且無關(guān)閉提示(這個功能太常用了)


3:讓一個鏈接自動提交:
如有一個鏈接:

則可以:







在STRUTS中有一個多個FRAME構(gòu)成的系統(tǒng).點擊注銷后想固定到某一頁面!(這個鬼費了我不少時間 ^_^ )
4:讓HTML也有JSP中的request.getParameter("");
HTML也可以通過JS來到得參數(shù),函數(shù)如下(我將它保存到了一個數(shù)組里面):






















































所以你以后就可以通過如:

的樣子來直接取了啦,c_courseID是參數(shù)名稱哦
5:在頁面動態(tài)顯示當(dāng)前時間




1000就表示了,每隔1000毫秒就更新一次aa里面的內(nèi)容.
6:對WEB頁面對象的常用操作,
.select()? 選中對象(文本框)的內(nèi)容
.focus()?? 讓某個對象獲取焦點
checked? 檢查單選按鈕是否處于選中狀態(tài)
若存的是一組單選按鈕,根據(jù)document的一些方法:
getElementById???? 獲取對 ID 標(biāo)簽屬性為指定值的第一個對象的引用。
getElementsByName???? 根據(jù) NAME 標(biāo)簽屬性的值獲取對象的集合。
getElementsByTagName???? 獲取基于指定元素名稱的對象集合。
可以用getElementsByName來解決,它是取得一些同名對象的集合,與getElementById(指定值的第一個對象的引用)不同.如下所示:












7:確定下拉框的值:


















HTML 如下:









刪除其中的一個option:
se.options.remove(1);
其中參數(shù)1表示下標(biāo)
8:使得某一對象不可用(可用剛改成false)
document.form1.submit2.disabled=true;
使得某一對象不可見(可見則改成visible)
document.form1.submit2.style.visibility="hidden";
9:日期以'yyyy-mm-dd'(2006-09-07 or 2006-9-17)





































































































再加一個比較函數(shù),剛剛寫的

























10:對一組單選按鈕的處理---是否選中or返回選中值

















11,從A頁面打開一個頁面B,從B中輸入相關(guān)信息后再從B頁面把信息傳到A頁面處理:
從A頁面打開B頁面的方法:







主要是其中的obj參數(shù)起作用.然后在B頁面 中返回:








注意這兒只取了主要部分:username,phone,emial均是在B頁面取得一些信息obj.addRow()中addRow是A頁面中定義的,如下:












12:得用JS在WEB頁面中動態(tài)增加行列:
這里主要用到了innerHTML, cells,rows,appendChild等一些方法與屬性有了它們基本上就OK了,更多可以參考HTML的參考手冊,可以做到如在DW更改界面一樣,感覺很爽(比如更改對象的title ,id ,style, name)!







主要用到了cloneNode方法,其它更多可以參考關(guān)于HTML的對象介紹,然后再通過appendChild來增加一行(在此是增加一行).當(dāng)然也可以自己定義一些元素來初始化innerHTML,as :


順便說一下關(guān)于刪除:

















注意這種方法刪除時,一不小心不犯錯了.一方面for(c2=child_len; c2>0; c2--)應(yīng)該是遞減的方式來遍歷(因為rows里面push的時候,與刪除的時候節(jié)點是反向的,當(dāng)然假如取rows的時候反向取也OK的),另一方面?dateTr.parentNode.rows.length-1不可以直接放到for里面(因為?dateTr.parentNode.rows.length-1的長值每在for里面跑一次就變一次,當(dāng)然是變小啦).
所以也可以如下處理:



























我這兒用到了復(fù)選框,當(dāng)然這并不影響刪除的效果實現(xiàn),它不過是一種刪除條件罷了(比如title也是哦)
13:第一次見到這樣的自定義函數(shù):






















應(yīng)用如下:







感覺蠻不錯!(原來這些是protype.js中的東東呢,呵呵 這二天看了下prototype.js原來它是為ruby寫的框架,不過這個東東確實不錯哦!)
14:javascript驗證表單時常用
"^-[0-9]*[1-9][0-9]*$" //負(fù)整數(shù)
"^-?\d+$" //整數(shù)
"^\d+(\.\d+)?$" //非負(fù)浮點數(shù)(正浮點數(shù) + 0)
"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$" //正浮點數(shù)
"^((-\d+(\.\d+)?)|(0+(\.0+)?))$" //非正浮點數(shù)(負(fù)浮點數(shù) + 0)
"^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$" //負(fù)浮點數(shù)
"^(-?\d+)(\.\d+)?$" //浮點數(shù)
"^[A-Za-z]+$" //由26個英文字母組成的字符串
"^[A-Z]+$" //由26個英文字母的大寫組成的字符串
"^[a-z]+$" //由26個英文字母的小寫組成的字符串
"^[A-Za-z0-9]+$" //由數(shù)字和26個英文字母組成的字符串
"^\w+$" //由數(shù)字、26個英文字母或者下劃線組成的字符串
"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$" //email地址
"^[a-zA-z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$" //url
呵呵 我一天添一些JS上來,可惜朋友們看不到,因為這"貼子"沉下去了.沒辦法,可是它們真的幫我不少忙,我自己的也常到這兒來取經(jīng)....
以后不用序號了,直接改用日期
06.7.18:今天我用JS產(chǎn)生一個checkbox,別的都沒事,就是在設(shè)置默認(rèn)讓它選中時花了些時間:
以下是代碼:
input = document.createElement("input");
???input.setAttribute("type","checkbox");
???//input.defaultChecked = true;---此語句可以直接在產(chǎn)生checkbox的時候讓它默認(rèn)選中
???input.setAttribute("value","1");
?? $('kdydx').appendChild(input);
???$('kdydx').lastChild.setAttribute("checked","ckecked");//要想通過setAttribute來設(shè)置,剛必須在appendChild之后
關(guān)于它的答案我在http://forum.java.sun.com/thread.jspa?threadID=628633&messageID=3606303找到的。
//打印
function send_dy(){
?var bdhtml=window.document.body.innerHTML;
?sprnstr="<!--startprint-->";
?eprnstr="<!--endprint-->";
?prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+17);
?prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
?window.document.body.innerHTML=prnhtml;
?window.print();
?window.document.body.innerHTML=bdhtml;
}
/**
?調(diào)用IE的打印控件打印TABLE
?tb為要打印的TABLE的ID
?pSzize為一頁的行數(shù)
**/
function tablePrint(tb,pSize,title){
?var nw = window.open('','','top=50,left=100,resizable=yes,width=800,height=600,titlebar=yes,menubar=no,status=no,location=no,scrollbars=yes');
?nw.document.open("text/html","GB2312")
?nw.document.write("<style media=print>");
?nw.document.write(".Noprint{display:none;}");//不需要打印的樣式
?nw.document.write(".PageNext{page-break-after: always;}");//
?nw.document.write(".data_Table{border-color:#000000;border-width:1px;border-style:solid;}");
?nw.document.write("</style>");
?nw.document.write("<style>");
?nw.document.write(".Mb_Input_Button{height:20px;border-left:1px solid #DAE8F7; border-top:1px solid #DAE8F7; border-right:1px solid #A0C4EB;border-bottom:1px solid #A0C4EB;background-color:#E4EBF3;padding-left:5px;padding-right:5px;margin:4px 5px 2px 0px;}");
?nw.document.write(".noShow{display:none;}");//打印預(yù)覽時不需要顯示的樣式
?nw.document.write("</style>");
?nw.document.write("<HEAD><TITLE> </TITLE></HEAD>");
?nw.document.write("<body>");
?nw.document.write("<div align='right'>");
?nw.document.write("<input type=button value='打印' onclick='document.all.WebBrowser.ExecWB(6,1);' class='NOPRINT Mb_Input_Button'> ");
??nw.document.write("<input type=button value='頁面設(shè)置' onclick='document.all.WebBrowser.ExecWB(8,1);' class='NOPRINT Mb_Input_Button'> ");
??nw.document.write("<input type=button value='打印預(yù)覽' onclick='document.all.WebBrowser.ExecWB(7,1);' class='NOPRINT Mb_Input_Button'> ");
?nw.document.write("</div>");
?nw.document.write("<OBJECT? id=WebBrowser? classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2? height=0? width=0 VIEWASTEXT></OBJECT>");
?nw.document.write("<div align='center' style='margin-top:5; margin-bottom:5'><b>"+title+"</b></div>");
?var obj=document.getElementById(tb);
?var trObj=obj.childNodes[0].childNodes;
?for(i=0;i<trObj.length;i++){
?? if((i!=0)&&(i%pSize==0)){
? ?trObj[i].className="PageNext";
? ?}
? }
?nw.document.write(document.getElementById(tb).outerHTML);
?nw.document.write("</body>");
}
/**
?調(diào)用IE的打印控件打印對象
?tb為要打印的TABLE的ID
?pSzize為一頁的行數(shù)
**/
function objPrint(tb,title){
?var nw = window.open('','','top=50,left=100,resizable=yes,width=800,height=600,titlebar=yes,menubar=no,status=no,location=no,scrollbars=yes');
?nw.document.open("text/html","GB2312")
?nw.document.write("<style media=print>");
?nw.document.write(".Noprint{display:none;}");//不需要打印的樣式
?nw.document.write(".PageNext{page-break-after: always;}");//
?nw.document.write(".data_Table{border-color:#000000;border-width:1px;border-style:solid;}");
?nw.document.write("</style>");
?nw.document.write("<style>");
?nw.document.write(".Mb_Input_Button{height:20px;border-left:1px solid #DAE8F7; border-top:1px solid #DAE8F7; border-right:1px solid #A0C4EB;border-bottom:1px solid #A0C4EB;background-color:#E4EBF3;padding-left:5px;padding-right:5px;margin:4px 5px 2px 0px;}");
?nw.document.write(".noShow{display:none;}");//打印預(yù)覽時不需要顯示的樣式
?nw.document.write("</style>");
?nw.document.write("<HEAD><TITLE> </TITLE></HEAD>");
?nw.document.write("<body>");
?nw.document.write("<div align='right'>");
?nw.document.write("<input type=button value='打印' onclick='document.all.WebBrowser.ExecWB(6,1);' class='NOPRINT Mb_Input_Button'> ");
??nw.document.write("<input type=button value='頁面設(shè)置' onclick='document.all.WebBrowser.ExecWB(8,1);' class='NOPRINT Mb_Input_Button'> ");
??nw.document.write("<input type=button value='打印預(yù)覽' onclick='document.all.WebBrowser.ExecWB(7,1);' class='NOPRINT Mb_Input_Button'> ");
??nw.document.write("<input type=button value='關(guān)閉' onclick='document.all.window.close();' class='NOPRINT'>");
?nw.document.write("</div>");
?nw.document.write("<OBJECT? id=WebBrowser? classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2? height=0? width=0 VIEWASTEXT></OBJECT>");
?nw.document.write("<div align='center' style='margin-top:5; margin-bottom:5'><b>"+title+"</b></div>");
?nw.document.write(document.getElementById(tb).outerHTML);
?nw.document.write("</body>");
}
/**
?中文英文混合時字符串的長度計算
?一個漢字2個字節(jié)
**/
String.prototype.length2 = function() {
??? var cArr = this.match(/[^x00-xff]/ig);
??? return this.length + (cArr == null ? 0 : cArr.length);
}
...?? ....