Common JavaScript code (5): javascript code
The article is from "PHP100 Chinese network"
28. The character size can be compared
Char = post. charAt (I );
If (! ('0' <= char & char <= '9 '))
29. Convert characters into numbers
Month = parseInt (char)
30. Switch to the specified connection when you click the option of non-null value.
<Select onchange = 'if (this. value! = "") Window. open (this. value) 'class = "textinput">
<Option selected> organizer </option>
<Option> ----------------- </option>
<Option value = "http://www.bjd.com.cn/"> Beijing Daily </option>
<Option value = "http://www.ben.com.cn/"> Beijing Evening News </option>
</Select>
31. Change the background color
<Td width = * class = dp bgColor = # FAFBFC onmouseover = "this. bgColor = '# ffff ';"
Onmouseout = "this. bgColor = '# FAFBFC';">
32. Change the background color of the text input box.
<Style>
. Input2 {background-image: url ('../images/inputbg.gif'); font-size: 12px; background-color:
# D0DABB; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
</Style>
<Input name = content type = text size = "47" class = "input2" maxlength = "50">
33. Changing the features of a horizontal line
<Hr size = "0" noshade color = "# C0C0C0">
34. Method of passing Parameters
<A href = "vote. asp? CurPage = 8 & id = 3488 "> 8 </a>
35. page navigation
<A href = "#1"> 1 </a>
<A href = "#2"> 2 </a>
<A href = "#3"> 3 </a>
<A href = "#4"> 4 </a>
<A href = "#5"> 5 </a>
<A href = "#6"> 6 </a>
<A href = "#7"> 7 </a>
<A name = "1"> dfdf </a>
<A name = "2"> dfdf </a> //
36. Press the two buttons together
If (event. ctrlKey & window. event. keyCode = 13 )//
37. Refresh the page
Javascript: this. location. reload ()//
38. Enable the buttons on the webpage
<Script language = "JavaScript">
Function haha ()
{
For (var I = 0; I <document. form1.elements. length; I ++)
{
If (document. form1.elements. name. indexOf ("bb ")! =-1)
Document. form1.elements. disabled =! Document. form1.elements. disabled;
}
}
</SCRIPT>
<BODY> <form name = form1>
<Input type = "button" NAME = "aa" value = cindy onclick = haha ()>
<Input type = "button" NAME = "bb" value = guoguo>
<Input type = "button" NAME = "bb" value = guoguo>
39. Text Movement
<Marquee scrollamount = 3 onmouseover = this. stop (); onmouseout = this. start ();>
40. Double-click the webpage to automatically run
<Script language = "JavaScript">
Var currentpos, timer;
Function initialize ()
{
Timer = setInterval ("scrollwindow ()", 1 );
}
Function SC ()
{
ClearInterval (timer );
}
Function scrollwindow ()
{
Currentpos = document. body. scrollTop;
Window. scroll (0, ++ currentpos );
If (currentpos! = Document. body. scrollTop)
SC ();
}
Document. onmousedown = SC
Document. ondblclick = initialize
</SCRIPT> //
41. Backward
<Input type = "button" onclick = window. history. back () value = back>
42. Forward
<Input type = "button" onclick = window. history. forward () value = forward>
43. Refresh
<Input type = "button" onclick = document. location. reload () value = reload>
44. Redirect to the specified webpage
Document. location = "http: // ww" or document. location. assign ("http://guoguo.com ")
45. display real-time on the webpage
<Script language = "JavaScript">
Var clock_id;
Window. onload = function ()
{
Clock_id = setInterval ("document.form1.txt clock. value = (new Date);", 1000)
}
</SCRIPT> //
46. files can be downloaded
Document. location. href = "target file "//
47. Connect to the database
Import java. SQL .*;
String myDBDriver = "sun. jdbc. odbc. JdbcOdbcDriver ";
Class. forName (myDBDriver );
Connection conn = DriverManager. getConnection ("jdbc: odbc: firm", "username", "password ");
Statement stmt = conn. createStatement ();
ResultSet rs1_stmt.exe cuteQuery (SQL );
Rs. getString ("column1 ");//
48. You can directly write the required content in the "div" of the page.
<Input type = "button" onclick = "a1.innerHTML = '<font color = red> * </font>'">
<Div id = a1> </div> //
49. You can change the connection format on the page so that it is a two-line connection.
<Style>
A: link {text-decoration: none; color: # 0000FF; font-family:}
A: visited {text-decoration: none; color: # 0000FF; font-family:}
A: hover {text-decoration: underline overline; color: FF0000}
</Style>
<Style>
A: link {text-decoration: none; color: # 0000FF; font-family:}
A: visited {text-decoration: none; color: # 0000FF; font-family:}
A: hover {text-decoration: underline overline line-through; color: FF0000}
TH {FONT-SIZE: 9pt}
TD {FONT-SIZE: 9pt}
Body {SCROLLBAR-FACE-COLOR: # A9D46D; SCROLLBAR-HIGHLIGHT-COLOR: # e7e7e7; SCROLLBAR-SHADOW-COLOR: # e7e7e7;
SCROLLBAR-3DLIGHT-COLOR: #000000; LINE-HEIGHT: 15pt; SCROLLBAR-ARROW-COLOR: # ffffff;
SCROLLBAR-TRACK-COLOR: # e7e7e7 ;}
INPUT {BORDER-TOP-WIDTH: 1px; PADDING-RIGHT: 1px; PADDING-LEFT: 1px; BORDER-LEFT-WIDTH: 1px; FONT-SIZE:
9pt; BORDER-LEFT-COLOR: # cccccc;
BORDER-BOTTOM-WIDTH: 1px; BORDER-BOTTOM-COLOR: # cccccc; PADDING-BOTTOM: 1px; BORDER-TOP-COLOR: # cccccc;
PADDING-TOP: 1px; HEIGHT: 18px; BORDER-RIGHT-WIDTH: 1px; BORDER-RIGHT-COLOR: # cccccc}
DIV, form, OPTION, P, TD, BR {FONT-FAMILY:; FONT-SIZE: 9pt}
Textarea, select {border-width: 1; border-color: #000000; background-color: # efefef; font-family:;
Font-size: 9pt; font-style: bold ;}
. Text {font-family: ""; font-size: 9pt; color: #003300; border: #006600 solid; border-width: 1px 1px
1px 1px}
</Style> complete css
50. Create a frame
<
Href = "javascript: newframe ('HTTP: // www.163.net/help/a_little/index.html', 'http://www.163.net/help/a_little
/A_13.html ') "> </a>
51. Write content to the file
<% @ 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. Read the file first and then write the file
<% @ 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 ();
%>