JS Code judgment collection (Part 2)
<Input type = "button" value = "login" tabindex = "4">
<Input type = "button" value = "register" tabindex = "4">
Function trim (inputstr) // place space, before obtaining the form information entered by the client,
Trim is used before submission. For example, "form1.org _ name. value = trim (form1.org _ name. value );"
{
If (! Inputstr. length> 0) return "";
Var starts = 0;
Var ends = inputstr. length;
While (starts <ends)
{
If (inputstr. substring (starts, starts + 1) = "")
Starts ++;
Else
Break;
}
While (starts <ends)
{
If (inputstr. substring (ends-1, ends) = "")
Ends --;
Else
Break;
}
Return inputstr. substring (starts, ends );
}
Function isvalidcode (inputs) // verify the zip code
{
Var I, temp;
Var isvalidcode = true;
Inputstr = trim (inputs );
If (inputstr. length = null | inputstr. length = 0 | inputstr. length! = 6) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9 "))
{
Isvalidcode = false;
Break;
}
}
Return isvalidcode;
}
Function isvalidtel (inputs) // verify the phone number
{
Var I, temp;
Var isvalidtel = true;
Inputstr = trim (inputs );
If (inputstr. length = null | inputstr. length = 0) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9" | temp = "-"))
{
Isvalidtel = false;
Break;
}
}
Return isvalidtel;
}
Function isrealnum (inputs) // check the real number (including the decimal point)
{
Var I, temp;
Var isrealnum = true;
Inputstr = trim (inputs );
If (inputstr. length = null | inputstr. length = 0) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9" | temp = "."))
{
Isrealnum = false;
Break;
}
}
Return isrealnum;
}
Function isnumeric (inputs) // check whether integer
{
Var I, temp;
Var isnumeric = true;
Inputstr = trim (inputs );
If (inputstr. length = null | inputstr. length = 0) return false;
// Isvalid = true;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9 "))
{
Isnumeric = false;
Break;
}
}
Return isnumeric;
}
Function isvalidide (inputs) // verify the ID card
{
Var I, temp;
Var isvalidide = true;
Inputstr = trim (inputs );
If (inputstr. length = null | inputstr. length = 0 | (inputstr. length! = 15 & inputstr. length! = 18) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9") | temp = "x" | temp = "X "))
{
Isvalidide = false;
Break;
}
}
Return isvalidide;
}
Function isvalidname (inputs) // verify account 2 ~ 15 digits (a string consisting of English letters and numbers only)
{
Var I, temp;
Var isvalidname = true;
Inputstr = trim (inputs );
If (inputstr. length = null | inputstr. length = 0 | inputstr. length> 15 | inputstr. length <2) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9") | (temp> = "a" & temp <= "z ") | (temp> = "A" & temp <= "Z ")))
{
Isvalidname = false;
Break;
}
}
Return isvalidname;
}
Function isvalidphoto (inputs) // verify the photo Extension
{
Var I, temp;
Var isvalidphoto = true;
Inputstr = trim (inputs );
If (inputstr. length = null | inputstr. length = 0) return true; // It is also allowed if no photo is available.
Temp = inputstr. substring (inputstr. lastIndexOf (".") + 1 );
Temp = temp. toLowerCase ();
If (! (Temp = "bmp" | temp = "jpg" | temp = "gif "))
{
Isvalidphoto = false;
}
Return isvalidphoto;
}
Function isvalidzgh (inputs) // verifies the employee ID with 8 digits (that is, it can only be a string consisting of English letters and numbers)
{
Var I, temp;
Var isvalidzgh = true;
Inputstr = trim (inputs );
If (inputstr. length = null | inputstr. length = 0 | inputstr. length! = 8) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9") | (temp> = "a" & temp <= "z ") | (temp> = "A" & temp <= "Z ")))
{
Isvalidzgh = false;
Break;
}
}
Return isvalidzgh;
}
Function isvalidxh (inputs) // check student ID 7 (that is, it can only be a string consisting of English letters and numbers)
{
Var I, temp;
Var isvalidxh = true;
Inputstr = trim (inputs );
If (inputstr. length = null | inputstr. length = 0 | inputstr. length! = 7) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9") | (temp> = "a" & temp <= "z ") | (temp> = "A" & temp <= "Z ")))
{
Isvalidxh = false;
Break;
}
}
Return isvalidxh;
}
Function isvalidkcid (inputs) // check the course number by five digits (that is, a string consisting of only digits)
{
Var I, temp;
Var isvalidkcid = true;
Inputstr = trim (inputs );
If (inputstr. length = null | inputstr. length = 0 | inputstr. length! = 5) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9 "))
{
Isvalidkcid = false;
Break;
}
}
Return isvalidkcid;
}
Function isvalidnamee (inputs) // verify account 4 ~ 20 digits (a string consisting of English letters and numbers only)
{
Var I, temp;
Var isvalidname = true;
Inputstr = trim (inputs );
If (inputstr. length = null | inputstr. length = 0 | inputstr. length> 20 | inputstr. length <4) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9") | (temp> = "a" & temp <= "z ") | (temp> = "A" & temp <= "Z ")))
{
Isvalidname = false;
Break;
}
}
Return isvalidname;
}
<Script language = "JavaScript">
Function login ()
{
Form1.UNAME. value = trim (form1.UNAME. value );
Form1.PWD. value = trim (form1.PWD. value );
Form1.PWD2. value = trim (form1.PWD2. value );
Form1.EMAIL. value = trim (form1.EMAIL. value );
Form1.NC. value = trim (form1.NC. value );
If (! Isvalidname (form1.UNAME. value ))
{
Alert ("Please note: the user name must be" 2 ~ 15 digits in English 』! ");
Form1.UNAME. focus ();
Return false;
}
Else if (! Isvalidname (form1.PWD. value ))
{
Alert ("Please note: the password must be" 2 ~ 15 digits in English 』! ");
Form1.PWD. focus ();
Return false;
}
Else if (! Isvalidname (form1.PWD2. value ))
{
Alert ("Please note: the password must also be" 2 ~ 15 digits in English 』! ");
Form1.PWD2. focus ();
Return false;
}
Else if (form1.PWD. value! = Form1.PWD2. value)
{
Alert ("the two passwords are inconsistent! ");
Form1.PWD. focus ();
Return false;
}
Else if (form1.EMAIL. value = "" | form1.EMAIL. value. length> 100)
{
Alert ("enter an email! ");
Form1.EMAIL. focus ();
Return false;
}
Else if (form1.NC. value = "" | form1.NC. value. length> 15)
{
Alert ("enter a nickname! ");
Form1.NC. focus ();
Return false;
}
Else if (window. confirm ("You are sure to submit! "))
Return true;
Else
Return false;
}
Function regedit ()
{
Var litop = (screen. height-162)/2;
Var lileft = (screen. width-360)/2;
Window. open ("/regedit. aspx", "reg", "titlebar = no, fullscreen = no, dependent = yes, height = 162, width = 360,
Top = "+ litop +", left = "+ lileft + ",
Toolbar = no, menubar = no, scrollbars = no, resizable = no,
Channelmode = no, status = no, location = no, directories = no ");
}
</Script>
1. copy disabled. Right-click Disabled!
<SCRIPT>
// Add page Protection
Function rf ()
{Return false ;}
Document. oncontextmenu = rf
Function keydown ()
{If (event. ctrlKey = true | event. keyCode = 93 | event. shiftKey = true) {return false ;}}
Document. onkeydown = keydown
Function drag ()
{Return false ;}
Document. ondragstart = drag
Function stopmouse (e ){
If (navigator. appName = 'netscape '& (e. which = 3 | e. which = 2 ))
Return false;
Else if
(Navigator. appName = 'Microsoft Internet Explorer '& (event. button = 2 | event. button = 3 )){
Alert ("no copyright, but do not copy it :)");
Return false;
}
Return true;
}
Document. onmousedown = stopmouse;
If (document. layers)
Window. captureEvents (Event. MOUSEDOWN );
Window. onmousedown = stopmouse;
</SCRIPT>
<Script language = "javascript">
Function JM_cc (ob ){
Var obj = MM_findObj (ob); if (obj ){
Obj.select({%js%obj.createtextrange(%%%js.exe cCommand ("Copy ");}
}
Function MM_findObj (n, d) {// v4.0
Var p, I, x; if (! D) d = document; if (p = n. indexOf ("? ")> 0 & parent. frames. length ){
D=parent.frames[n.substring(p%1%].doc ument; n = n. substring (0, p );}
If (! (X = d [n]) & d. all) x = d. all [n]; for (I = 0 ;! X & I <d. forms. length; I ++) x = d. forms [n];
For (I = 0 ;! X & d. layers & I <d. layers. length; I ++) xw.mm_findobj(n,d.layers.doc ument );
If (! X & document. getElementById) x = document. getElementById (n); return x;
}
</Script>
2. Mutual conversion between JS and HTML
<Body>
<Style>
Body {font-size: 9pt}
Textarea {color = "#707888"; font-family: "verdana "}
. Inputs {color = "#707888"; border: 1px solid; background: # f4f4f4}
</Style>
Enter the format you want to convert, either JavaScript or DHtml.
<Br>
<Textarea id = "codes" style = "width: 730; height: 300">
</Textarea>
<Br>
<Button class = "inputs">
Clear output
</Button>
<Button class = "inputs">
Select all codes
</Button>
<Button class = "inputs">
Copy code
</Button>
<Button class = "inputs">
Paste code
</Button>
<Button class = "inputs">
Convert Js to Html
</Button>
<Button class = "inputs">
Convert Html to Js
</Button>
<Button class = "inputs">
Click Show source file
</Button>
<Button class = "inputs">
Preview code [F12]
</Button>
<Br>
This is the output format window:
<Br>
<Textarea id = "outputs" style = "width: 730; height: 300"> </textarea>
<Br>
A bad message: the JavaScript-to-Html part only supports
<Br>
Author: FlashSoft2000 QQ: 14433548
<Input id = "hide" style = 'display: none'>
<Script>
// Define the title
Document. title = "multi-function webpage conversion"
// Display the webpage source file
Function writes ()
{
Outputs. value = document. body. outerHTML;
}
// Clear the Output Window
Function clears ()
{
Outputs. innerHTML = '';
}
// Replace a specified character
// N1 string, n2 to be replaced, n3 to be replaced
Function commute (n1, n2, n3)
{
Var a1, a2, a3 = 0, a0 =''
A1 = n1.length;
A2 = n2.length;
For (x = 0; x <= (a1-a2); x ++)
{
If (n1.substr (x, a2) = n2)
{
A0 + = n1.substring (a3, x );
A0 + = n3;
X + = (a2-1 );
A3 = x + 1;
}
}
If (a3 <a1) a0 + = n1.substring (a3, a1)
{
Return a0;
}
}
// Convert JavaScript to DHtml
Function js2html ()
{
Hide. value = codes. value
Hide. value = commute (hide. value ,'\\"','"');
Hide. value = commute (hide. value, 'document. write ("','');
Hide. value = commute (hide. value ,'")','');
Hide. value = commute (hide. value, '<script> ','');
Hide. value = commute (hide. value, '<\/script> ','');
Outputs. value = hide. value
}
// Convert DHtml to JavaScript
Function html2js ()
{
Hide. value = codes. value
Hide. value = commute (hide. value ,'"','\\"');
Hide. value = commute (hide. value ,'\\','\\\\');
Hide. value = commute (hide. value, '<\/script>', '<\/script> ');
Outputs. value = "<script> document. write (\" "+ hide. value +" \ ") <\/script>"
}
// Preview the code
Function seeHtm ()
{
Open().doc ument. write ("<title> test code window </title>" + outputs. value );
}
// Preview with the shortcut key F12
Document. onkeydown = seeHtms
Function seeHtms ()
{
If (event. keyCode = 123 ))
{
Open().doc ument. write ("<title> test code window </title>" + outputs. value );
}
}
// Select all codes
Function ta ()
{
Outputs. select ()
}
// Copy the code
Function tc ()
{
Document.exe cCommand ("Copy ")
}
// Paste the code
Function tp ()
{
Outputs. focus ()
Document.exe cCommand ("Paste ")
}
</Script>
Advertisement JS Code Effect Daquan
1. [Normal Results]
Nowadays, many website advertisements are in full swing. Now I will introduce the common code usage methods for floating couplet advertisements. The results are displayed at a resolution of 1024*768, the image can be automatically hidden at a resolution of 800*600 to avoid page hiding affecting the visitor's browsing content. The following code is required to achieve the effect:
Var delta = 0.015.
Var collection;
Function floaters (){
This. items = [];
This. addItem =
Function (id, x, y, content)
{
Document. write ('<DIV id =' + id + 'style = "Z-INDEX: 0; POSITION: absolute; width: 80px; height: 60px; left:' + (typeof (x) = 'string '? Eval (x): x) + '; top:' + (typeof (y) = 'string '? Eval (y): y) + '">' + content + '</DIV> ');
Var newItem = {};
NewItem. object = document. getElementById (id );
NewItem. x = x;
NewItem. y = y;
This. items [this. items. length] = newItem;
}
This. play =
Function ()
{
Collection =
This. items
SetInterval ('play () ', 10 );
}
}
Function play ()
{
If (screen. width <= 800)
{
For (var I = 0; I <collection. length; I ++)
{
Collection. object. style. display = 'none ';
}
Return;
}
For (var I = 0; I <collection. length; I ++)
{
Var followObj = collection. object;
Var followObj_x = (typeof (collection. x) = 'string '? Eval (collection. x): collection. x );
Var followObj_y = (typeof (collection. y) = 'string '? Eval (collection. y): collection. y );
If (followObj. offsetLeft! = (Document. body. scrollLeft + followObj_x )){
Var dx = (document. body. scrollLeft + followObj_x-followObj.offsetLeft) * delta;
Dx = (dx> 0? 1:-1) * Math. ceil (Math. abs (dx ));
FollowObj. style. left = followObj. offsetLeft + dx;
}
If (followObj. offsetTop! = (Document. body. scrollTop + followObj_y )){
Var dy = (document. body. scrollTop + followObj_y-followObj.offsetTop) * delta;
Dy = (dy> 0? 1:-1) * Math. ceil (Math. abs (dy ));
FollowObj. style. top = followObj. offsetTop + dy;
}
FollowObj. style. display = '';
}
}
Var theFloaters =
New floaters ();
TheFloaters. addItem ('followdiv1 ', 'document. body. clientWidth-100 ', 0, '</a> <br> <a href = aD link address target = _ blank> </> 'target = _ blank );
TheFloaters. addItem ('followdiv2', 0, 0, '<br> <a href = aD link address target = _ blank> </a>' target = _ blank );
TheFloaters. play ();
Save the above Code as a JS file and call it on the page to achieve this effect! Modify the ad image address and connection address!