// Usage: If the address is test.htm?t1=1&t2=2&t3=3, then you can get: GET["t1"], GET["t2"], GET["t3"]
function get_get(){
querystr = window.location.href.split("?")
if(querystr[1]){
GETs = querystr[1].split("&" )
GET =new Array()
for(i=0;i tmp_arr = GETs[i].split("=")
key=tmp_arr [0]
GET[key] = tmp_arr[1]
}
}
return querystr[1];
}
65. Native JavaScript implements universal selection of all Method
function checkall(form, prefix, checkall) {
var checkall = checkall ? checkall : 'chkall';
for(var i = 0; i < form.elements.length; i ) {
var e = form.elements[i];
if(e.type=="checkbox"){
e.checked = form.elements[checkall].checked;
}
}
}
66. Native JavaScript implements a common method to unselect all
function uncheckAll(form) {
for (var i=0;i
var e = form.elements[i];
if (e.name != 'chkall')
e.checked=!e.checked;
}
}
67. Native JavaScript implements a common method for opening a form
function openWindow(url,windowName,width,height){
var x = parseInt(screen.width / 2.0) - (width / 2.0);
var y = parseInt(screen.height / 2.0) - (height / 2.0);
var isMSIE= (navigator.appName == "Microsoft Internet Explorer");
if (isMSIE) {
var p = "resizable=1,location=no,scrollbars=no,width=";
p = p width;
p = p ",height=";
p = p height;
p = p ",left=";
p = p x;
p = p ",top=";
p = p y;
retval = window .open(url, windowName, p);
} else {
var win = window.open(url, "ZyiisPopup", "top=" y ",left=" x ",scrollbars=" scrollbars " ,dialog=yes,modal=yes,width=" width ",height=" height ",resizable=no" );
eval("try { win.resizeTo(width, height); } catch(e) { }");
win.focus();
}
}
68. Native JavaScript determines whether it is a client device
function client(o){
var b = navigator.userAgent.toLowerCase();
var t = false;
if (o == 'isOP'){
t = b.indexOf('opera') > -1;
}
if (o == 'isIE') {
t = b.indexOf('msie') > -1;
}
if (o == 'isFF'){
t = b.indexOf('firefox') > ; -1;
}
return t;
}
69. Native JavaScript gets the value of the radio button
function get_radio_value(field){
if(field&&field.length){
for(var i=0;i< field.length;i ){
if(field[i].checked){
return field[i].value;
}
}
}else {
return ;
}
}
70. Get the value of the checkbox with native JavaScript
function get_checkbox_value(field){
if(field&&field.length){
for(var i=0;i if(field[i].checked && !field [i].disabled){
return field[i].value; >(71~80) Verification This article is mainly about 10 commonly used form verification functions, including email, dangerous characters, verification length, verification URL, verification of decimals, integers, floating point numbers and other commonly used verifications. With these Code snippets, normal form validation does not require jquery validation plug-in, I hope it can help everyone. . .
71. Native JavaScript determines whether it is an email address
Copy the code
The code is as follows:
}}
72. Native JavaScript determines whether there are dangerous characters in the list
Copy code
The code is as follows:
}}
73. Native JavaScript determines whether the string is greater than the specified length
Copy code
The code is as follows:
74. Native JavaScript determines that the string is case-insensitive for the URL
Copy code
The code is as follows:
else return true;
}
return false;
}
75. Native JavaScript Determine whether the string is a decimal
Copy code
The code is as follows:
}
76. Native JavaScript determines whether a string is an integer
Copy code
The code is as follows :
}
77. Native JavaScript determines whether a string is a floating point number
Copy code
The code is as follows:
function isFloat( str ) {
for(i=0;i if ((str.charAt(i)<"0" || str .charAt(i)>"9")&& str.charAt(i) != '.'){
return false;
}
}
return true;
}
78. Native JavaScript determines whether the characters are A-Za-z English letters
function isLetters( str ){
var re=/^[A-Za-z] $/;
if (str.match(re) == null)
return false;
else
return true;
}
79. Native JavaScript determines whether a string is a postal code
function isValidPost( chars ) {
var re=/^d{6}$/;
if (chars.match (re) == null)
return false;
else
return true;
}
80. Native JavaScript determines whether the character is empty NULL
function isNULL( chars ) {
if (chars == null)
return true;
if (jsTrim(chars).length==0)
return true;
return false;
}
81. Native JavaScript uses regular expressions to extract page code All URLs in
var aa = document.documentElement.outerHTML. match(/(url(|src=|href=)["']*([^"'()<>[] ] )["')]*|(http://[w-.] [^"'()<>[] ] )/ig).join("rn").replace(/^(src=|href=|url()["']*|["'> ) ]*$/igm,"");
alert(aa);
82. Native JavaScript uses regular expressions to clear the same array (low efficiency)
Array.prototype.unique=function(){
return this.reverse().join (",").match(/([^,] )(?!.*1)/ig).reverse();
}
83. Native JavaScript uses regular expressions to clear the same Array of (high efficiency)
String.prototype.unique= function(){
var x=this.split(/[rn] /);
var y='';
for(var i=0;i if(!new RegExp("^" x[i].replace(/([^w])/ig,"\$1") "$","igm").test(y)){
y =x[i] "rn"
}
}
return y
}
84. Native JavaScript uses regular expressions to sort alphabetically and array each line Sort
function SetSort(){
var text= K1.value.split(/[rn]/).sort().join("rn");//Order
var test=K1.value.split(/[rn]/).sort(). reverse().join("rn");//Reverse order
K1.value=K1.value!=text?text:test;
}
85. Reverse native JavaScript string Sequence
function IsReverse(text){
return text .split('').reverse().join('');
}
86. Native JavaScript uses regular expressions to clear scripts in html code
function clear_script(){
K1.value=K1.value.replace(/< script.*?>[sS]*?|s on[a-zA-Z]{3,16}s?=s?"[sS]*?"|s on[a-zA -Z]{3,16}s?=s?'[sS]*?'|s on[a-zA-Z]{3,16}s?=[^ >] /ig,"");
}
87. Native JavaScript dynamically executes JavaScript scripts
function javascript(){
try{
eval(K1.value);
}catch(e){
alert(e.message);
}
}
88. Native JavaScript dynamically executes VBScript scripts
function vbscript (){
try{
var script=document.getElementById("K1").value;
if(script.trim()=="")return;
window.execScript(' On Error Resume Next n' script 'n If Err.Number<>0 Then n MsgBox "Please enter the correct VBScript script!",48,"Script error!" n End If',"vbscript")
} catch(e){
alert(e.message);
}
}
89. Native JavaScript implements the amount capitalization conversion function
function transform(tranvalue) {
try {
var i = 1;
var dw2 = new Array("", "10,000", "100 million"); //Large unit
var dw1 = new Array("十", "百", "千"); //Small unit
var dw = new Array("zero", "一", "二", "三" , "四", "五", "鲁", "旒", "八", "九"); //Use
for the integer part //The following is converted from lowercase to uppercase and displayed in the total uppercase text box
//Separate integers and decimals
var source = splits(tranvalue);
var num = source[0];
var dig = source[1];
//Convert the integer part
var k1 = 0; //Small unit
var k2 = 0; //Large unit
var sum = 0;
var str = "";
var len = source [0].length; //The length of the integer
for (i = 1; i <= len; i) {
var n = source[0].charAt(len - i); //Get A number at a certain digit
var bn = 0;
if (len - i - 1 >= 0) {
bn = source[0].charAt(len - i - 1); //Get the number before a certain digit
}
sum = sum Number(n);
if (sum != 0) {
str = dw[Number(n) ].concat(str); //Get the uppercase number corresponding to the number and insert it into the front of the str string
]. len - i - 1 >= 0) { //Within the range of numbers
if (k1 != 3) { //Add smaller units
if (bn != 0) {
str = dw1 [k1].concat(str);
}
k1 ;
} else { //Do not add small units, increase units
k1 = 0;
var temp = str.charAt (0); If (TEMP == "Wan" || Temp == "billion") // If there is no number in front of the large unit, go to the large unit
STR = Str.Substr (1, Str. length - 1);
str = dw2[k2].concat(str);
sum = 0;
}
}
if (k1 == 3) //Small unit to One thousand is the next major unit
{
k2 ;
}
}
//Convert the decimal part
var strdig = "";
if (dig != "" ) {
var n = dig.charAt(0);
if (n != 0) {
strdig = dw[Number(n)] "angle"; //Add numbers
}
var n = dig.charAt(1);
if (n != 0) {
strdig = dw[Number(n)] "points"; //Add numbers
}
}
str = "yuan" strdig;
} catch(e) {
return "0 yuan";
}
return str;
}
//Disassemble Split integers and decimals
function splits(tranvalue) {
var value = new Array('', '');
temp = tranvalue.split(".");
for (var i = 0; i < temp.length; i ) {
value[i] = temp[i];
}
return value;
}
90. Native JavaScript Large collection of commonly used regular expressions
Copy code
The code is as follows:
Regular expression matching Chinese characters: [u4e00-u9fa5]
Matching double-byte characters (including Chinese characters): [^x00-xff]
Regular expression matching blank lines :
[s| ]*r
Regular expression matching HTML tags: <(.*)>.*1>|<(.*) />
Regular expression matching leading and trailing spaces Expression: (^s*)|(s*$)
Regular expression matching IP address:/(d).(d).(d).(d)/g
Matching Email address Regular expression: w ([- .]w )*@w ([-.]w )*.w ([-.]w )*
Regular expression matching URL: http://(/ [w-] .) [w-] (/[w- ./?%&=]*)?
sql statement: ^(select|drop|delete|create|update|insert).*$
Non-negative integer: ^d $
Positive integer: ^[0-9]*[1-9][0-9]*$
Non-positive integer: ^((-d )|(0 ) )$
Negative integer: ^-[0-9]*[1-9][0-9]*$
Integer: ^-?d $
Non-negative floating point number: ^d (. d )?$
Positive floating point number: ^((0-9) .[0-9]*[1-9][0-9]*)|([0-9]*[1-9] [0-9]*.[0-9] )|([0-9]*[1-9][0-9]*))$
Non-positive floating point number: ^((-d .d )?)|(0 (.0 )?))$
English string: ^[A-Za-z] $
English uppercase string: ^[A-Z] $
English lowercase string: ^ [a-z] $
English character and numeric string: ^[A-Za-z0-9] $
English and numeric string with underline: ^w $
E-mail address: ^[w-] (. [w-] )*@[w-] (.[w-] ) $
URL: ^[a-zA-Z] ://(w (-w )*)(.(w (-w )*))*(?s*)?$ or: ^http://[A-Za-z0-9] .[A-Za-z0-9] [/=?%-&_~`@[] ': !]*([^<>""])*$
Postal code: ^[1-9]d{5}$
Phone number: ^(((d{2,3 }))|(d{3}-))?((0d{2,3})|0d{2,3}-)?[1-9]d{6,7}(-d{1,4 })?$
Mobile phone number: ^(((d{2,3}))|(d{3}-))?13d{9}$
Double-byte characters (including Chinese characters) :^x00-xff
Matches leading and trailing spaces: (^s*)|(s*$)
Matches HTML tags: <(.*)>.*1>|<(. *) />
matches empty lines:
[s| ]*r
Extract network links in the information: (h|H)(r|R)(e|E)(f|F) *= *('|")?(w|\| /|.) ('|"| *|>)?
Extract the email address in the message: w ([- .]w )*@w ([-.]w )*.w ([-. ]w )*
Extract the picture link in the message: (s|S)(r|R)(c|C) *= *('|")?(w|\|/|.) ('| "| *|>)?
Extract the IP address in the information: (d).(d).(d).(d)
Extract the Chinese mobile phone number in the information: (86)*0* 13d{9}
Extract the Chinese landline phone number in the information: ((d{3,4})|d{3,4}-|s)?d{8}
Extract the Chinese phone number in the information Number (including mobile and landline): ((d{3,4})|d{3,4}-|s)?d{7,14}
Extract the Chinese postal code in the information: [1- 9]{1}(d ){5}
Extract floating point numbers (i.e. decimals) in the information: (-?d*).?d
Extract any number in the information: (-?d*) (.d )?
IP: (d ).(d ).(d ).(d )
Telephone area code: ^0d{2,3}$
Tencent QQ number: ^[1- 9]*[1-9][0-9]*$
Account number (starts with a letter, allows 5-16 bytes, allows alphanumeric underscores): ^[a-zA-Z][a-zA-Z0 -9_]{4,15}$
Chinese, English, numbers and underline: ^[u4e00-u9fa5_a-zA-Z0-9] $
91. Native JavaScript implements form change event resize Operation (compatible with all browsers)
(function() {
var fn = function(){
var w = document.documentElement ? document.documentElement.clientWidth : document.body.clientWidth
, r = 1255
,b = Element.extend(document .body)
,classname = b.className