1. automatically select text in the text box
<Input type = "text" name = "mtext" size = "100" width = 20 value = "Text to be selected, move the mouse up to see :) "onmouseover =" focus (); select (); ">
2. input box restrictions
<Input type = "text" name = "txtmonth" value = ""
Onblur = "If (this. value <1 | this. value> 12)
{Alert ('month input is incorrect! ');
This. Focus () ;}>
3. Only numbers can be entered in the restricted input box.
<Input type = text name = txtpostalcode onkeypress = "If (event. keycode <45 | event. keycode> 57) event. returnvalue = false;">
4. Press enter to switch to the next line.
<Input onkeydown = "If (event. keycode = 13) event. keycode = 9" name = "text1">
5. Pop-up normal window and full screen display
<Script language = "JavaScript" type = "text/JavaScript">
VaR winh = Window. Screen. Height-58;
VaR winw = Window. Screen. Width-10;
</SCRIPT>
<A href = 'javascript:; 'onclick = "window. Open ('search _ grmx. asp? SID = <% = RS ("Sid") %> & rq_year = <% = year (RS ("RQ ")) %> & rq_month = <% = month (RS ("RQ") %> ', 'newwindow', 'scrollbars = Yes, Top = 1, Left = 1, width = '+ winw +', Height = '+ winh + '')"> link text
</A>
6. js Verification
<Script language = JavaScript>
<! --
Function checkform ()
{
If (document. form1.skr. value = ""){
Alert ("required ");
Form1.skr. Focus ();
Return false;
}
Return true;
}
// -->
</SCRIPT>
<Form name = "form1" method = "Post" Action = "enter. asp" onsubmit = "Return checkform ();">
7. Select All and delete
<Script language = "JavaScript">
<! -- Begin
VaR checkflag = "false ";
Function check (field ){
If (checkflag = "false "){
For (I = 0; I <field. length; I ++ ){
If (field [I]. Disabled = false ){
Field [I]. Checked = true;
}
}
Checkflag = "true ";
Return "cancel all selections ";
}
Else {
For (I = 0; I <field. length; I ++ ){
Field [I]. Checked = false;
}
Checkflag = "false ";
Return "select all ";
}
}
// End -->
</SCRIPT>
<Input type = "checkbox" name = "list" value = "<% = pic_id %>">
<Input name = "button" type = button onclick = "This. value = check (this. Form. List)" class = "bottom" value = "select all">
<Input name = "Submit" type = submit class = "bottom" value = "delete">
8. Text focus
<Body text = "#000000" bgcolor = "# eff1fd" onLoad = "document. form1.txm. Focus ();" scroll = "no">
9. The limit can only be input (0 ~ 9, ~ Z )﹕
<HTML>
<Head>
<Title> untitled document </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = big5">
<Script language = JavaScript>
<! --
Function ischinese (){
VaR Reg =/[^ a-z0-9 _]/g
If (Reg. Test (document. form1.text3. Value )){
Alert ("enter 0-9 and lowercase A-Z ﹗");
Form1.text3. Focus ();
Return false;
} Else {
Return true ;}
}
// -->
</SCRIPT>
</Head>
<Body>
<Form name = "form1" method = "Post" Action = "ABC. asp" onsubmit = "Return ischinese ();">
<Input name = "text3" type = "text" size = "15" value = "">
<Input type = "Submit" name = "Submit" value = "Submit">
</Form>
</Body>
</Html>
Only numeric amounts can be entered in the restricted input box
<Input type = text name = txtpostalcode onkeypress = "If (event. keycode <45 | event. keycode> 57) event. returnvalue = false;">
1. oncontextmenu = "window. event. returnvalue = false"
Bottom shield right-click
<Table border oncontextmenu = return (false)> <TD> NO </table>
Available for table
2. <body onselectstart = "Return false"> cancel
Select and prevent Replication
3. onpaste = "Return false"
Do not paste
4. oncopy = "Return false;" oncut = "Return false ;"
Prevent Replication
5. <LINK rel = "shortcut icon" href = "favicon. ICO"> before the IE Address Bar
Change to your own icon
6. <LINK rel = "bookmark" href = "favicon. ICO"> You can select
Show your icon
7. <input style = "ime-mode: Disabled">
Disable Input Method
8. Always carry the framework
<Script language = "JavaScript"> <! --
If (window = Top) top. Location. href = "frames.htm ";
// Frames.htm is the webpage
// --> </SCRIPT>
9. Prevent Frame
<Script language = JavaScript> <! --
If (top. location! =
Self. Location) top. Location = self. location;
// --> </SCRIPT>
10. <NoScript> <IFRAME src = *. html> </iframe> </NoScript>
Page cannot be saved
11. <input type = button value = view webpage source code
Onclick = "window. Location = 'view-Source: '+
'Http://www.csdn.net/' ">
12. How to use ASP to check whether the visitor has used an agent?
<% If request. servervariables ("http_x_forwarded_for") <> ""
Then
Response. Write "<font color = # ff0000> you have passed the proxy server ,"&
_
"The real IP address is
"& Request. servervariables (" http_x_forwarded_for ")
End if
%>
13. Obtain the absolute position of the control
// Javascript
<Script language = "JavaScript">
Function getie (e ){
VaR T = E. offsettop;
VaR L = E. offsetleft;
While (E = E. offsetparent ){
T + = E. offsettop;
L + = E. offsetleft;
}
Alert ("Top =" + T + "/nleft =" + l );
}
</SCRIPT>
// VBScript
<Script language = "VBScript"> <! --
Function getie ()
Dim t, L, A, B
Set a = Document. All. img1
T = Document. All. img1.offsettop
L = Document. All. img1.offsetleft
While a. tagname <> "body"
Set a = A. offsetparent
T = T + A. offsettop
L = L + A. offsetleft
Wend
Msgbox "Top =" & T & CHR (13) & "Left =" & L, 64, "Get control position"
End Function
--> </SCRIPT>
14. The cursor stops at the end of the text box.
<Script language = "JavaScript">
Function CC ()
{
VaR E = event. srcelement;
VaR r = E. createTextRange ();
R. movestart ('character ', E. value. Length );
R. Collapse (true );
R. Select ();
}
</SCRIPT>
<Input type = text name = text1 value = "123" onfocus = "CC ()">
15. determine the source of the previous page
ASP:
Request. servervariables ("http_referer ")
Javascript:
Document. referrer
16. Minimize, maximize, and close the window
<Object ID = HH1
Classid = "CLSID: ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<Param name = "command" value = "minimize"> </Object>
<Object ID = HH2
Classid = "CLSID: ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<Param name = "command" value = "maximize"> </Object>
<Object ID = hh3
Classid = "CLSID: adb880a6-d8ff-11cf-9377-00aa003b7a11">
<Param name = "command" value = "close"> </Object>
<Input type = button value = minimized onclick = hh1.click ()>
<Input type = button value = maximized onclick = hh2.click ()>
<Input type = button value = Disable onclick = hh3.click ()>
This example applies to IE
Solve the problem of large table support in content
TD style = "word-break: Break-all">
Print the page: <br clear = all style = 'page-break-before: alway'>
Big Table support problems
Javascript form submission restrictions
Author: Admin Source: site original hits: 2719 updated on:
<HTML>
<Head>
<Title> untitled document </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Script language = JavaScript>
<! --
Function checkform ()
{
If (document. form1.xm. value = ""){
Alert ("enter your name! ");
Form1.xm. Focus ();
Return false;
}
Return true;
}
// -->
</SCRIPT>
</Head>
<Body onload = "document. form1.xm. Focus ();">
<Form name = "form1" Action = "ABC. asp" method = "Post" onsubmit = "Return checkform ();">
<P> name
<Input name = "XM" type = "text" id = "XM">
</P>
<P>
<Input type = "Submit" name = "Submit" value = "Submit">
</P>
</Form>
</Body>
</Html>
========================================================== ====================================
The simplest JavaScript code for displaying time on the webpage
<Div id = "webjx">
<SCRIPT>
Setinterval ("webjx. innerhtml = new date (). tolocalestring () + 'Week' + 'may 15, 1234 five or six '. charat (new date (). get Day (); ", 1000 );
</SCRIPT>
</Div>