51.向文件中寫內容 <%@ page import="java.io.*" %> <% String str = "print me"; //always give the path from root. This way it almost always works. String nameOfTextFile = "/usr/anil/imp.txt"; try { PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile)); pw.println(str); //clean up pw.close(); } catch(IOException e) { out.println(e.getMessage()); } %> 52.先讀文件再寫文件 <%@ page language = "java" %> <%@ page contentType = "text/html; charSet=gb2312" %> <%@ page import ="java.util.*" %> <%@ page import ="java.lang.*" %> <%@ page import ="javax.servlet.*" %> <%@ page import ="javax.servlet.jsp.*" %> <%@ page import ="javax.servlet.http.*" %> <%@ page import="java.io.*" %> eryrytry <% int count=0; FileInputStream fi =new FileInputStream ("count.txt"); ObjectInputStream si= new ObjectInputStream (fi); count =si.readInt(); count++; out.print(count); si.close(); FileOutputStream fo =new FileOutputStream ("count.txt"); ObjectOutputStream so= new ObjectOutputStream (fo); so.writeInt(count); so.close(); %> 53.直線型輸入框 <INPUT name=Password size=10 type=password style="border-left-width: 0; border-right-width: 0; border-top-width: 0; border-bottom-style: solid; border-bottom-width: 1; background-color: #9CEB9C"> 54.能夠將背景改成按鈕性狀,經過改變css改變屬性 <td width="65" align="center" bgcolor="#E0E0E0" onmouseover=this.className='mouseoverbt'; onmouseout=this.className='mouseout';><a href="tm.asp?classid=76"><font color="#000000">錄音筆</font></a></td> <style> .mouseoverbt { background-image: url(http://www.yongle.com.cn/img/btbgw64h20y.gif); background-repeat: no-repeat; } .mouseout { background-color: #E0E0E0; } </style> 55.同時按下CTRL和Q鍵 document.onkeydown=function() { if(event.ctrlKey&&event.keyCode==81) {alert(1)} }// 56.如下是一個完整的顯示hint的代碼,其思想是當鼠標停留是將div中的內容顯示在鼠標出,當鼠標移出後在將該div隱 藏掉 --------------------------------------------------------------------------------------------------------- ------------ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <style> #hint{ width:198px; border:1px solid #000000; background:#99ff33; position:absolute; z-index:9; padding:6px; line-height:17px; text-align:left; top: 1520px; } </style> <SCRIPT LANGUAGE="JavaScript"> <!-- function showme() { var oSon=window.document.getElementById("hint"); if (oSon==null) return; with (oSon) { innerText=guoguo.value; style.display="block"; style.pixelLeft=window.event.clientX+window.document.body.scrollLeft+6; style.pixelTop=window.event.clientY+window.document.body.scrollTop+9; } } function hidme() { var oSon=window.document.getElementById("hint"); if (oSon==null) return; oSon.style.display="none"; } //--> </SCRIPT> <BODY> <text id=guoguo value=ga> <a href=# onmouseover=showme() onmouseout=hidme() onmousemove=showme() son=hint>dfdfd</a> <div id=hint style="display:none"></div> </BODY> </HTML> --------------------------------------------------------------------------------------------------------- ------------ 57.彈出窗口 方法一:<body onload="openwen()"> 瀏覽器讀頁面時彈出窗口; 方法二:<body onunload="openwen()"> 瀏覽器離開頁面時彈出窗口; 方法三:用一個鏈接調用:<a href="#" onclick="openwin()">打開一個窗口</a> 注意:使用的"#"是虛鏈接。 方法四:用一個按鈕調用:<input type="button" onclick="openwin()" value="打開窗口"> 什麼時候裝載script 58.動態改變字體的大小 function doZoom(size) { document.getElementById('zoom').style.fontSize=size+'px' } function aa() { var newWin=window.open(url); newWin.document.form1.text1.value=value1; }改變彈出窗口上域的屬性 opener.document.form2.text2.value=value2;改變父窗口的域的值 59.判斷是何種瀏覽器 var name = navigator.appName; if (name == "Microsoft Internet Explorer") alert("IE"); else if (name == "Netscape") alert("NS");// 60.vbsscript肯定框 <script language="VBScript"> <!-- MsgBox "肯定刪除嗎?", 4 //--> </script>// 61.複製內容到剪切板 function JM_cc(bb) { var ob=eval("document.form1."+bb); ob.select(); js=ob.createTextRange(); js.execCommand("Copy"); }// 62.java中創建數據庫鏈接取數據 public void init() { String url="jdbc:odbc:javadata"; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection(url,"sa","");//mssql database user SA and password DatabaseMetaData dma=con.getMetaData(); System.out.println("Connect to"+dma.getURL()); System.out.println(";Driver "+dma.getDriverName()); System.out.println(";Version "+dma.getDriverVersion()); System.out.println(""); Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery("select * from company.dbo.TB_NAME where number=1");//Sql rs.next(); String dispresult=rs.getString("name"); System.out.println(dispresult);// Instead,you can display it in Paint() or use AWT etc. rs.close(); stmt.close(); con.close(); } catch(SQLException ex) { System.out.println("!!!SQL Exception !!!"); while(ex!=null) { System.out.println("SQLState:"+ex.getSQLState()); System.out.println("Message:"+ex.getMessage()); System.out.println("Vendor:"+ex.getErrorCode()); ex=ex.getNextException(); System.out.println(""); } } catch(java.lang.Exception ex) { ex.printStackTrace(); } }// 63.最小化窗口 window.blur()// 64.文檔的路徑 document.URL// 65.定時執行某段程序 setTimeout("change_color()",600); 66.設置爲主頁 function makeHome(){ netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite"); navigator.preference("browser.startup.homepage", location.href); }// 67.設置爲收藏 function addFav(){ if(ie) window.external.AddFavorite(location.href,'WWW.OGRISH.COM : GROTESQUE MOVIES AND PICTURES'); if(ns) alert("Thanks for the bookmark!\n\nNetscape users click OK then press CTRL-D"); }// 68.判斷cookie是否可用 navigator.cookieEnabled;// 69.顯示有模式的有頁面的彈出窗口 function setbgcolor_onclick() { var color = showModalDialog("/mailpage/compose/colorsel.html",0,"help=0"); if (color != null) { document.compose.bgcolor.value = color; } }// 70.截取小數點後兩位 var a=3454545.4454545; alert(a.toFixed(2));// 71.禁止選擇頁面上的文字來拷貝 <script> function noEffect() { with (event) { returnValue = false; cancelBubble = true; } return; } </script> <body onselectstart="noEffect()" oncontextmenu="noEffect()">// 72.屏蔽右鍵菜單 oncontextmenu="event.returnValue = false"// 73.事件禁止起泡 event.cancelBubble = true// 74.禁止在輸入框打開輸入法 <input style="ime-mode: disabled">// 75.屏蔽漢字和空格 <input name="txt"><input type="submit" onClick="alert(!/[^ -}]|\s/.test(txt.value))">// 76.用javascript判斷文件是否存在 function Exists(filespec) { if (filespec) { var fso; fso = new ActiveXObject("Scripting.FileSystemObject"); alert(fso.FileExists(filespec)); } } 選擇圖片 <input type=file name=f1><p> <input type="submit" onClick="Exists(f1.value)">// 77.得到當前的文本框選中的文字 <input onmouseup="alert(document.selection.createRange().text)" value=123>// 78.跳轉至目標頁面,同時不可返回 <a href="javascript:location.replace('http://www.sohu.com/')">sohu.com</a>// 79.得到當前的行是表格的第幾行 <script> function getrow(obj) { if(event.srcElement.tagName=="TD"){ curRow=event.srcElement.parentElement; alert("這是第"+(curRow.rowIndex+1)+"行"); } } </script> <table border="1" width="100%" onclick=getrow(this)> <tr> <td width="20%"> </td> <td width="20%"> </td> <td width="20%"> </td> <td width="20%"> </td> <td width="20%"> </td> </tr> <tr> <td width="20%"> </td> <td width="20%"> </td> <td width="20%"> </td> <td width="20%"> </td> <td width="20%"> </td> </tr> </table>// 80.刪除表格某行,xx表示某行,下標從0開始計算 document.all.myTable.deleteRow(xx)// 81.動態的向表格中添加行 <table id="t1" border="1"> </table> <script language="JavaScript"> function add() { t1.insertRow().insertCell().innerHTML = '<input name="test'+t1.rows.length+'">'; }//