常見的JavaScript代碼(六),javascript代碼

來源:互聯網
上載者:User

常見的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()//


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.