Common JavaScript code (6): javascript code
Article from "PHP Chinese network"
53. Linear input box
<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. You can change the background to button traits and change the attributes by changing 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"> recording pen </font> </a> </td>
<Style>
. Mouseoverbt
{
Background-image: url ();
Background-repeat: no-repeat;
}
. Mouseout
{
Background-color: # E0E0E0;
}
</Style>
55. Press CTRL and Q at the same time.
Document. onkeydown = function ()
{
If (event. ctrlKey & event. keyCode = 81)
{Alert (1 )}
}//
56. The following is a complete code for displaying hint. The idea is that when the mouse stays, the content in the div is displayed with the mouse, and the div is hidden after the mouse is removed.
<! 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={doc ument. getElementById ("hint ");
If (oSon = null) return;
With (oSon)
{
InnerText = guoguo. value;
Style. display = "block ";
Style.pixelleft;{event.clientx;{doc ument. body. scrollLeft + 6;
Style.pixeltoptop{event.clienty}{doc ument. body. scrollTop + 9;
}
}
Function hidme ()
{
Var oson={doc ument. 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>
Bytes ---------------------------------------------------------------------------------------------------------
------------
57. pop-up window
Method 1: <body onload = "openwen ()"> A window pops up when the browser reads the page;
Method 2: <body onunload = "openwen ()"> A window pops up when the browser leaves the page;
Method 3: call with a connection: <a href = "#" onclick = "openwin ()"> open a window </a>
Note: "#" is a virtual connection.
Method 4: call with a button: <input type = "button" onclick = "openwin ()" value = "open window"> when to load script
58. dynamically change the font size
Function doZoom (size)
{
Document. getElementById ('zoom '). style. fontSize = size + 'px'
}
Function aa ()
{
Var newWin = window. open (url );
NewWin.doc ument. form1.text1. value = value1;
} Changed the domain attributes in the pop-up window.
Opener.doc ument. form2.text2. value = value2; change the value of the field in the parent window.
59. Determine the browser
Var name = navigator. appName;
If (name = "Microsoft Internet Explorer ")
Alert ("IE ");
Else if (name = "Netscape ")
Alert ("NS ");//
60. vbsscript confirmation box
<Script language = "VBScript">
<! --
MsgBox "are you sure you want to delete it? ", 4
// -->
</Script> //
61. Copy the content to the clipboard
Function JM_cc (bb)
{
Var ob = eval ("document. form1." + bb );
Ob. select ();
Js = ob. createTextRange ();
Js.exe cCommand ("Copy ");
}//
62. Establish a database connection in java to retrieve data
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 rs1_stmt.exe cuteQuery ("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. Minimize the window
Window. blur ()//