推荐些实用js函数:
//打开弹出窗口
function winOpen (strURL,strName,width,height)
{
theWindow = window.open (strURL,strName,"width="+width+" height="+height+" scrollbars=yes left="+(1024-width)/2+" top="+(768-height)/2);
if (theWindow.opener == null) theWindow.opener = window;
if (window.focus) theWindow.focus();
}
//验证邮件
function verifyEmailAddress(strEmail){
var myReg = /^[_a-zA-Z0-9_-_._-]+@([_a-zA-Z0-9_-]+\.)+[a-zA-Z]{2,3}$/;
return myReg.test(strEmail);
}
/*****************************************************************
**** 判断是否为日期数据 (lhm) 例子:itIsDate("2009-10-7" , "-") *****
*****************************************************************/
function itIsDate(DateString , Dilimeter)
{
if (DateString==null) return false;
if (Dilimeter=='' || Dilimeter==null)
Dilimeter = '-';
var tempy='';
var tempm='';
var tempd='';
var tempArray;
if (DateString.length<8 && DateString.length>10)
return false;
tempArray = DateString.split(Dilimeter);
if (tempArray.length!=3)
return false;
if (tempArray[0].length==4)
{
tempy = tempArray[0];
tempd = tempArray[2];
}
else
{
tempy = tempArray[2];
tempd = tempArray[1];
}
tempm = tempArray[1];
var tDateString = tempy + '/'+tempm + '/'+tempd+' 8:0:0';//加八小时是因为我们处于东八区
var tempDate = new Date(tDateString);
if (isNaN(tempDate))
return false;
if (((tempDate.getUTCFullYear()).toString()==tempy) && (tempDate.getMonth()==parseInt(tempm)-1) && (tempDate.getDate()==parseInt(tempd)))
{
return true;
}
else
{
return false;
}
}
/*****************************************************************
**** 求字符串的字节长度 (lhm) *****
*****************************************************************/
function byteLength(paraString)
{
var strValue =new String(paraString);
var strLength = strValue.length;
var numLength =0;
for (globle_i =0 ; globle_i<strLength;globle_i++){
var ASCIIValue =strValue.charCodeAt(globle_i);
if ( ASCIIValue > 0 && ASCIIValue < 127 )
numLength = numLength + 1
else
numLength = numLength + 2
}
return numLength;
}
/*****************************************************************
**** 去除空格 (lhm) *****
*****************************************************************/
function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
return stringToTrim.replace(/\s+$/,"");
}
String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,"");}
String.prototype.ltrim = function() {return this.replace(/^\s+/,"");}
String.prototype.rtrim = function() {return this.replace(/\s+$/,"");}
/*****************************************************************
**** 复选框的全选与取消 (LHM) *****
*****************************************************************/
function CheckAll(form){
var length = form.itemId.length;
var tocheck = form.chkall.checked;
if (length)
for (var i=0; i<length; i++){
if (form.itemId[i].disabled != true){
form.itemId[i].checked = tocheck;
}
}
else {
if (form.itemId.disabled !=true){
form.itemId.checked = tocheck;
}
}
}
/*****************************************************************
**** 删除处理 (LHM) *****
*****************************************************************/
function del_btn (form,strMsg,actionurl){
var result = false;
var length = form.itemId.length;
if (form.itemId.checked) { //只有一条记录时执行此语句
result = true;
}
for (var i=0; i<length; i++){
if (form.itemId[i].checked){
result = true;
break;
}
}
if (!result){
alert ("没有选择任何项目!");
return false;
}else{
if (confirm('\n'+strMsg)){
form.action = actionurl;
return true;
}
return false;
}
}
/*****************************************************************
**** 转化字符串 (LHM) *****
*****************************************************************/
function conversion_code(paraString)
{
strResult = "";
j=0;
for (i=0;i<paraString.length;i++){
Char = String1.charAt(i);
if (Char=="'"){
strResult = strResult + paraString.substring(j,i)+"\\"+"\'";
j=i+1;
}
return strResult;
}
}
/*****************************************************************
**** 数字输入控制处理 (LHM) *****
*****************************************************************/
function InputIntNumberCheck(){
//为支持IE 或 Netscape
var theEvent=window.event || arguments.callee.caller.arguments[0];
var elm ;
var ver = navigator.appVersion;
if (ver.indexOf("MSIE") != -1){ // IE
if ( !((theEvent.keyCode >=48)&&(theEvent.keyCode<=57))){
theEvent.keyCode=0;
}
}else{ // Netscape
if ( !((theEvent.which >=48)&&(theEvent.which<=57))){
theEvent.stopPropagation();
theEvent.preventDefault();
}
}
//
}
/*****************************************************************
**** 有小数点数字输入控制处理 (LHM) *****
*****************************************************************/
function InputLongNumberCheck(){
if ( !((window.event.keyCode >=48)&&(window.event.keyCode<=57) || window.event.keyCode ==46)){
window.event.keyCode=0;
}
var theEvent=window.event || arguments.callee.caller.arguments[0];
var elm ;
var ver = navigator.appVersion;
if (ver.indexOf("MSIE") != -1){ // IE
if (!((theEvent.keyCode>=48)&&(theEvent.keyCode<=57) || theEvent.keyCode ==46)){
theEvent.keyCode=0;
}
}else{ // Netscape
if ( !((theEvent.which >=48)&&(theEvent.which<=57) || theEvent.which ==46)){
theEvent.stopPropagation();
theEvent.preventDefault();
}
}
}
/*****************************************************************
**** 换页处理 *****
*****************************************************************/
function toWhichPage(objform, whichPage){
objform.whichPage.value = whichPage;
objform.submit();
}
/*************************liuxch *******************************
**** 获取cookie内容 *****
*****************************************************************/
function getCookie( name ){
var nameOfCookie = name + "=";
var x = 0;
while ( x <= document.cookie.length ){
var y = (x+nameOfCookie.length);
if ( document.cookie.substring( x, y ) == nameOfCookie ) {
if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
endOfCookie = document.cookie.length;
return unescape( document.cookie.substring( y, endOfCookie ) );
}
x = document.cookie.indexOf( " ", x ) + 1;
if ( x == 0 ) break;
}
return "";
}
/*****************************************************************
**** 设置cookie内容、过期时间 *****
*****************************************************************/
function setCookie( name, value, expiredays ) {
var todayDate = new Date();
todayDate.setDate( todayDate.getDate() + expiredays );
document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}
/*****************************************************************
**** 检查输入字符 (lhm) *****
'// islegality:输入的字符是否为给定的字符
'//返回值:bool
*****************************************************************/
function islegality(checkstrpass){
var checkokpass="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
for (i=0; i<checkstrpass.length; i++) {
ch=checkstrpass.charAt(i);
for (j=0;j<checkokpass.length; j++){
if (ch==checkokpass.charAt(j))
break;
}
if (j==checkokpass.length){
return false; //函有特别字符时返回false
break;
}
}
return true;
}
/**
* 检查输入是否中文
*/
function ck_chinese(value_) {
return escape(value_).indexOf("%u")!=-1
}
分享到:
相关推荐
各种js验证 实用javascript函数 倒计时 实时显示系统时间 身份证验证 验证网址是否合法 验证Email格式是否正确 等等
JavaScript范例宝典 javascript工作中实例参考的很有帮助哦,留给自己以后工作中备用;另外因为整个文件很大(超过了csdn的限制15M),本人不得已按功能拆分上传。上传耗了我快一个小时,希望大家支持
NULL 博文链接:https://wangchao-0625.iteye.com/blog/337590
实用的JavaScript函数(jsp).rar实用的JavaScript函数(jsp).rar实用的JavaScript函数(jsp).rar
css-functions, CSSinJS用于构建CSS函数的JavaScript实用程序函数 JavaScript函数来构建CSS函数这个包函数返回返回等价CSS函数语法的函数。 在非生产模式下将自动进行值验证。用户定义函数现在我们 ship 25个函数。...
js功能 更多实用的js函数。
JavaScript绘图函数大全,非常实用
Util.js 是对常用函数的封装,方便在实际项目中使用,主要内容包含:数组类、浏览器类、日期类、函数类、数学类、媒体类、节点类、对象类、字符串类、类型检测类、正则表达式类等内容。
实用函数式Javascript.zip
收集了js常用函数,比较全面,实用。方便网络开发者查阅。
JavaScript中的50+个实用工具函数小结 JavaScript可以做很多出色的事情,本篇文章给大家整理50+个实用工具函数,可以帮助你提高工作效率并可以帮助调试代码 1、isStatic: 检测数据是不是除了symbol外的原始数据...
一些常用且实用的原生JavaScript函数.docx
Ramda一个JavaScript程序员的实用函数库
一组用于JavaScript函数的实用程序函数。 安装 如果要在浏览器中使用Bit.js ,只需下载build/bit.min.js并将其包含在页面中: < script src =" ./js/bit.min.js " > </ script > 也可以通过: npm...
31种asp、js函数收藏_代码很实用.txt
本文收集了100个原生态JavaScript编写的常用、实用自定义函数,需要的朋友可以参考下
js validator通用函数及实例包含了validator的通用函数及实例,在开发WEB项目中非常实用,非常高兴和大家分享
xTool.js是一个免费轻量级实用的javascript函数库,提供了一套简洁实用功能!
Pathre: Node的路径解析器实用程序函数