Home Web Front-end JS Tutorial js general javascript function library organization_javascript skills

js general javascript function library organization_javascript skills

May 16, 2016 pm 06:03 PM
function library

Copy code The code is as follows:

/*
* Contains jquery-1.3.2.min. js
*/
document.write("");
/*
* Public parameters
*/
var hostUrl='http://' window.location.host; //Get the website host header
/*
* Horizontally centered left value
*/
function HorCenter(x){
return (document.documentElement.clientWidth-x)/2;
}
/*
* Vertically centered top value
*/
function VerCenter(y){
return (document.documentElement.clientHeight-y)/2 document.documentElement.scrollTop;
}
/*
* Remove the spaces at the left and right ends
*/
function Trim(str){
return str.replace(/(^s*)|(s*$)/g, "");
}
/*
* Determine the email address and return true/false
*/
function IsEmail(email){
var Expression=/w ([- .']w )*@w ([-.]w )*.w([-.]w )*/;
var objExp=new RegExp(Expression);
return objExp.test(email);
}
/*
* Determine the user name and return true/false
*/
function IsUser(user){
var Expression=/^(?!_)(?!.*?_$)(w|[u4E00- u9FA5])*$/; //Only numbers, Chinese characters, letters, and underscores can be combined, and underscores cannot be at the beginning or end
var objExp=new RegExp(Expression);
return objExp.test(user);
}
/*
* Determine the mobile phone number
*/
function IsMobile(mobile){
var Expression=/^1[3458]{1}[0-9]{ 9}$/;
var objExp=new RegExp(Expression);
return objExp.test(mobile);
}
/*
* Judge non-negative integer and return true/false
*/
function IsInt(intval){
var Expression=/^d $/;
var objExp=new RegExp(Expression);
return objExp.test(intval);
}
/*
* Judge the number and return true/false
*/
function IsNum(num){
return !isNaN(num);
}
/*
* Determine RMB (money) and return 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);
}
/ *
* Calculate the length of the string, Chinese numbers are recorded as two, English numbers are recorded as one
*/
function GetByteLen(sChars){
return sChars.replace(/[^x00-xff] /g,"xx").length;
}
/*
* Limit the longest 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 cookie
*/
function SetCookie(name,value)
{
var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(2var path=( 3var domain=(4var secure=(5document.cookie=name "=" escape(value) ((expires==null)?"":("; expires=" expires.toGMTString())) ((path==null)?"": ("; path=" path)) ((domain==null)?"":("; domain=" domain)) ((secure==true)?"; secure":"");
}
/*
* Get cookie
*/
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;
}
/*
* checkBox select all, clear all
*
* Quote
*
*
*/
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 Copy for multiple browsers
*/
function CopyValue(strValue){
if(IsIE())
{
clipboardData.setData("Text",strValue);
alert("Copy successfully");
}
else
{
Copy(strValue);
alert("Copy successfully");
}
}
/*
* Determine IE browser
*/
function IsIE(number){
if(typeof(number)!=number)
{
return!!document.all ;
}
}
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Golang function library usage cost and license agreement Golang function library usage cost and license agreement Apr 19, 2024 pm 02:03 PM

The cost of using the Go function library mainly depends on its pricing model, which is generally divided into two types: free open source and paid license; the license agreement stipulates the terms of use, and common types include MIT, GPL and BSD licenses; be sure to read it before using the function library License agreement, such as "github.com/stretchr/testify" function library adopts MIT license, allowing free use and modification.

Detailed explanation of C++ function library: guide to extension of system functions Detailed explanation of C++ function library: guide to extension of system functions May 04, 2024 pm 01:48 PM

The C++ function library is a collection of predefined functions and objects used to enhance the functionality of C++ programs. The standard C++ function library provides input/output, mathematical calculations, string processing, containers and algorithm functions. Extended C++ libraries such as Boost, Qt, Armadillo and Eigen provide a wider range of capabilities such as advanced algorithms, GUI development and linear algebra calculations. In a practical case, we used the Boost function library to convert a string to lowercase, showing how to use the function library to extend a C++ program.

Learn and apply the main functions in the numpy function library Learn and apply the main functions in the numpy function library Jan 03, 2024 am 09:20 AM

Master the key functions and their applications in the numpy function library. In the fields of data science and machine learning, numpy is a very important Python library that provides high-performance multi-dimensional array objects and various mathematical functions. This article will introduce some key functions in numpy and provide specific code examples to help readers better understand and use these functions. Numpy array creation and initialization Numpy provides a variety of methods to create and initialize arrays. Among them, the most basic is to use numpy.arra

How do I create a PHP library and distribute it to others? How do I create a PHP library and distribute it to others? Apr 27, 2024 pm 09:12 PM

This article describes the steps for creating, testing, and distributing PHP libraries to simplify development and improve code quality. Create a function library: Create a main PHP script in the folder and define the functions. Test function library: Create a test script that includes the function library and calls functions to assert output. Distribute the function library: through Composer: create the composer.json file, specify the package information and run Composer. Via GitHub: Upload the function library to the repository, provide a download link, or explain how to install it. Distribute zip file: Create a zip file containing the library files and distribute it on GitHub.

PHP 8.3 update: provides more development tools and function libraries PHP 8.3 update: provides more development tools and function libraries Nov 27, 2023 pm 12:09 PM

PHP is a widely used programming language that plays an important role in the field of web development. The advantage of PHP is its flexibility and ease of use, allowing developers to quickly create powerful web applications. Every year, PHP is updated and improved to meet changing needs. Recently, the PHP8.3 update was released, providing developers with more development tools and function libraries. In this article, we will explore some of the important updates in PHP 8.3. First, PHP8.3 introduces more development

An essential programming tool book: Recommended C language function library An essential programming tool book: Recommended C language function library Feb 23, 2024 pm 01:09 PM

An essential programming tool book: Recommended C Language Function Library With the development of computer science and programming, programmers often use a variety of function libraries in daily development to facilitate them to implement complex functions. . Among them, the C language function library is one of the most classic and commonly used. This article will recommend a very practical C language function library and provide some specific code examples. First of all, the C Language Function Library Encyclopedia refers to a comprehensive reference manual that contains various C language functions. It not only introduces the standard C library functions, but also includes some

Comparison of the advantages and disadvantages of Golang function libraries Comparison of the advantages and disadvantages of Golang function libraries Apr 18, 2024 pm 09:12 PM

The function libraries of the Golang standard library each have their own advantages and disadvantages, and it is important to understand the differences. The fmt function library provides formatted output, but with limited control; the log function library records logs, but has no customizable levels; the regexp function library handles regular expressions, but has limited performance; the sort function library sorts basic data types; the strings function library operates characters string, but lacks advanced features. Consider these factors to choose the most appropriate library.

How to create a PHP function library and integrate it into another PHP project? How to create a PHP function library and integrate it into another PHP project? Apr 26, 2024 pm 01:33 PM

The steps to create a PHP function library are as follows: 1. Create a function library file and write functions; 2. Integrate the function library into another project through require_once() or spl_autoload_register(). For example, a function library that calculates the total price of an order is created and integrated and used in another script.

See all articles