常見的JavaScript代碼(六),javascript代碼
文章來自“PHP中文網”
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();
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()//