_javascript Techniques for JS Universal JavaScript function library Finishing

Source: Internet
Author: User
Tags setcookie
Copy Code code as follows:

/*
* Contains Jquery-1.3.2.min.js
*/
document.write ("<script language= ' javascript ' src= ' js/jquery-1.3.2.min.js ' ></script>");
/*
* Public Parameters
*/
var hosturl= ' http://' +window.location.host; Get web site Host Header
/*
* Center left value horizontally
*/
function Horcenter (x) {
Return (document.documentelement.clientwidth-x)/2;
}
/*
* Center Top value Vertically
*/
function Vercenter (y) {
Return (document.documentelement.clientheight-y)/2+document.documentelement.scrolltop;
}
/*
* Delete the left and right sides of the space
*/
function Trim (str) {
Return Str.replace (/(^\s*) | ( \s*$)/g, "");
}
/*
* Judge the mailbox, return to True/false
*/
function Isemail (email) {
var expression=/\w+ ([-+. '] \w+) *@\w+ ([-.] \w+) *\.\w ([-.] \w+) * * *;
var objexp=new RegExp (Expression);
return objexp.test (email);
}
/*
* Judge user name, return true/false
*/
function IsUser (user) {
var expression=/^ (?!) _)(?!. *?_$) (\w| [\u4e00-\u9fa5]) *$/; Can only be numeric, Chinese, letter, underline combination, underline can not at the beginning or end
var objexp=new RegExp (Expression);
return objexp.test (user);
}
/*
* Judge Mobile phone number
*/
function IsMobile (MOBILE) {
var expression=/^1[3458]{1}[0-9]{9}$/;
var objexp=new RegExp (Expression);
Return objexp.test (MOBILE);
}
/*
* Judge nonnegative integers, return true/false
*/
function Isint (intval) {
var expression=/^\d+$/;
var objexp=new RegExp (Expression);
Return Objexp.test (intval);
}
/*
* Judge the number and return to True/false
*/
function Isnum (num) {
return!isnan (num);
}
/*
* Judge RMB (money) and return to True/false
*/
function Ismoney (Money) {
var expression=/^ ([1-9]\d+|0) \.\d{2}| ( [1-9]\d+|0)) $/;
var objexp=new RegExp (Expression);
Return Objexp.test (Money);
}
/*
* The length of the calculation string, in Chinese two, the English digit is written as a
*/
function Getbytelen (schars) {
Return Schars.replace (/[^\x00-\xff]/g, "xx"). Length;
}
/*
* Limit the length of the input string
*/
function Getbyteval (ssource, Ilen) {
if (Ssource.replace (/[^\x00-\xff]/g, "xx"). Length<=ilen)
{
return ssource;
}
Else
{
var str= "";
var l=0;
var Schar;
For (var i=0;schar=ssource.charat (i); i++)
{
Str+=schar;
l+= (Schar.match (/[^\x00-\xff]/)!= null 2:1);
if (L>=ilen)
{
Break
}
}
return str;
}
}
/*
* Write cookies
*/
function Setcookie (name,value)
{
var argv=setcookie.arguments;
var argc=setcookie.arguments.length;
var expires= (2&LT;ARGC) argv[2]:null;
var path= (3&LT;ARGC) argv[3]:null;
var domain= (4&LT;ARGC) argv[4]:null;
var secure= (5&LT;ARGC) Argv[5]:false;
document.cookie=name+ "=" +escape (value) + (expires==null)? ":("; Expires= "+expires.togmtstring ()) + (Path==null)" ":("; Path= "+path") + (domain==null)? ":("; domain= "+domain)" + ((secure==true)? "; Secure ":" ");
}
/*
* Get cookies
*/
function GetCookie (name) {
var search = name + "=";
var returnvalue = "";
if (Document.cookie.length > 0)
{
offset = document.cookie.indexOf (search);
if (offset!=-1)
{
Offset + + search.length;
End = Document.cookie.indexOf (";", offset);
if (end = = 1)
end = Document.cookie.length;
Returnvalue=unescape (document.cookie.substring (offset,end));
}
}
Return returnvalue;
}
/*
* Full selection of checkbox, Total elimination
*
* Reference
* <input name= "chkbox" type= checkbox "onclick=" Checkall (This, ' Form1 ')/>
* <input name= "chkbox" type= "checkbox" value= "" class= "Chk"/>
*/
function Checkall (obj,objform) {
if (obj.checked==true) {
$ (' # ' +objform+ ' Input:checkbox.chk '). each (function () {
this.checked= ' checked ';
});
}
else{
$ (' # ' +objform+ ' Input:checkbox.chk '). each (function () {
This.checked= ';
});
}
}
/*
* Support for multiple browser replication
*/
function Copyvalue (strvalue) {
if (Isie ())
{
Clipboarddata.setdata ("Text", strvalue);
Alert ("Successful copy");
}
Else
{
Copy (strvalue);
Alert ("Successful copy");
}
}
/*
* Judge IE browser
*/
function Isie (number) {
if (typeof (number)!=number)
{
return!! document.all;
}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.