`
huanyq2008
  • 浏览: 166512 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

JS函数库 common.js

阅读更多
/************************************************************ 
相关函数说明 

$(id) 根据元素id返回对象 
GetLen(str) 计算字符串的长度,汉字占两个字符 
InitHeight(obj) 自适应Iframe高度,Iframe元素的高度随里面的内容自适应高度 
Close() 关闭窗口,FF默认不支持窗口关闭 
GetElementByName(name, i) 根据元素名称返回对象,可能会有多个元素同名,i表示序号 
ArrayRemove(array, n) 删除数组中指定位置的元素 
************************************************************/ 

function $(id) 
{ 
   return document.getElementById(id); 
} 


function GetLen(str) 
{ 
   return str.replace(/[^\x00-\xff]/g, '**').length; 
} 


function InitHeight(obj) 
{ 
   obj.style.height = (obj.contentWindow.document.body.scrollHeight + 20) + 'px'; 
} 


function Close() 
{ 
   window.opener = null; 
   window.open('', '_self'); 
   window.close(); 
} 


// 根据元素名称返回对象 
function GetElementByName(name, i) 
{ 
   if (typeof(i) == 'undefined') i = 0; 

   var els = document.getElementsByName(name); 
   if (els.length > 0) 
   { 
       return els[i]; 
   } 
   return null; 
} 


function ArrayRemove(array, n) 
{ 
   if(n < 0 || n >= array.length) return array; 

   // slice 方法返回数组的一段 
   // concat 方法将当前数组和指定的一个或多个数组整成一个 
   return array.slice(0, n).concat(array.slice(n + 1, array.length)); 
} 


/************************************************************ 
Cookie 静态类。 
功能:操作 Cookie。 

1.Cookie.Exist(name) 检查 Cookie 是否存在 
2.Cookie.Get(name) 读取 Cookie 的值,没有该 Cookie 返回 null 
3.Cookie.Remove(name, path, domain) 删除 Cookie 
4.Cookie.Add(name, value, expires, path, domain, secure) 添加 Cookie,更新和添加都一样 
5.Cookie.Append(name, value) 追加值,用"|"分隔 
************************************************************/ 
var Cookie = 
{ 
   Expires : 365, 
   Exist : function(name) 
   { 
       if (this.Get(name)) return true; 
       return false; 
   }, 
   Get : function(name) 
   { 
       var strCookies = document.cookie; 
       var cookieName = name + '=';  // Cookie名称 
        
        
       // 取得值的开始位置 
       var valueBegin = strCookies.indexOf(cookieName); 
       if (valueBegin == -1) return null;  // 没有此Cookie 
        
       // 取得值的结尾位置 
       var valueEnd = strCookies.indexOf(';', valueBegin); 
       if (valueEnd == -1) valueEnd = strCookies.length; // 是最后一个Cookie 

       // 取得Cookie值 
       var value = strCookies.substring(valueBegin + cookieName.length, valueEnd); 
       return value; 
   }, 
   Add : function(name, value, expires) 
   { 
       if (typeof(expires) == 'undefined') expires = this.Expires; 

       var strCookie = name + '=' + value; 
       if (expires) 
       { 
           // 计算Cookie的期限, 参数为天数 
           var curTime = new Date(); 
           curTime.setTime(curTime.getTime() + expires*24*60*60*1000); 
           strCookie += '; expires=' + curTime.toGMTString(); 
       } 
       document.cookie = strCookie; 
   }, 
   Append : function(name, value, expires) // 值用“|”分隔 
   { 
       var oldValue = this.Get(name); 

       if (oldValue != null) value = oldValue + '|' + value; 

       this.Add(name, value, expires); 
   }, 
   Remove : function(name) 
   { 
       var strCookie; 

       // 检查Cookie是否存在 
       if (this.Exist(name)) 
       { 
           // 设置Cookie的期限为己过期 
           strCookie = name + '=;'; 
           document.cookie = strCookie; 
       } 
   } 
} 



/************************************************************ 
Ajax 静态类。 
功能:操作 XMLHttpRequest,实现 Ajax 

Ajax.LoadXml(url, method, callback) 
url 请求的地址 
method 请求的方法,如GET或POST 
callback 请求响应后,回调的方法,这个是自定义的函数名称 

************************************************************/ 
var Ajax = 
{ 
   LoadXml : function(url, method, callback) 
   { 
       var xmlHttp; 
       if (window.ActiveXObject) // IE 
       { 
           xmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); 
       } 
       else if (window.XMLHttpRequest) // FF 
       { 
           xmlHttp = new XMLHttpRequest(); 
       } 
       if(!xmlHttp) 
       { 
           window.alert('不能创建 XMLHttpRequest 对象!'); 
           return false; 
       } 

       xmlHttp.open(method, url, true); 
       xmlHttp.onreadystatechange = function() 
       { 
           if(xmlHttp.readyState != 4) return; 
           callback(xmlHttp); 
       } 
       xmlHttp.send(null); 
   } 
} 

 

 

2010.11.9添加:

//获取url参数
function getArgs( ) {
    var args = new Object( );
    var query = location.search.substring(1);     // Get query string
    var pairs = query.split("&");                 // Break at ampersand
    for(var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');          // Look for "name=value"
        if (pos == -1) continue;                  // If not found, skip
        var argname = pairs[i].substring(0,pos);  // Extract the name
        var value = pairs[i].substring(pos+1);    // Extract the value
        value = decodeURIComponent(value);        // Decode it, if needed
        args[argname] = value;                    // Store as a property
    }
    return args;                                  // Return the object
}

function GetQueryString( sProp ) {
	var re = new RegExp( sProp + "=([^\\&]*)", "i" );
	var a = re.exec( document.location.search );
	if ( a == null )
		return "";
	return a[1];          
};

 

2010-12-11

function clickForAuto(){
    var nodeId = "test";
    if(document.all){
    	document.getElementById(nodeId).click();
    }else{
	    var evt = document.createEvent("MouseEvents");
	    evt.initEvent("click", true, true);
	    document.getElementById(nodeId).dispatchEvent(evt);
    }    
}

 

分享到:
评论

相关推荐

    外部函数接口LibFFI.zip

    而 “Libffi” 库只提供了最底层的、与架构相关的、完整的”FFI”,因此在它之上必须有一层来负责管理两种语言之间参数的格式转换。 高级语言编译器产生代码时都会依据一系列的规则,这些规则十分必要,特别是对...

    JavaScript库ChannelPlate.zip

    ChannelPlate 是一个在跨文档通信(MessageChannel) 中用来发送消息的 JavaScript 库。覆盖了从 W3C 到 Chrome 浏览器扩展中的跨文档通信接口,通常用于这几种情况下:  1) 共用构造函数  2) 统一 API 接口 3...

    transport.js

    \js\common.js \js\transport.js \themes\modify\library\member_info.lbi \admin\js\selectzone.js \admin\templates\topic_edit.htm \admin\templates\menu.htm \admin\templates\topic_edit.htm ...

    JavaScript完全自学宝典 源代码

    Calculate1.java 计算浮点数运算结果并调用页面中JavaScript函数的Applet。 Calculate1.class Calculate1.java的字节码文件。 第16章(\c16) 示例描述:介绍JavaScript访问本地文件的各种方法。 16.1....

    通用javascript脚本函数库 方便开发

    将下面代码保存为Common.js 类库功能: 1.Trim(str)--去除字符串两边的空格 2.XMLEncode(str)--对字符串进行XML编码 3.ShowLabel(str,str)--鼠标提示功能(显示字符,提示字符) 可以设置显示的提示的文字的...

    sharepoint-library:共享点库

    common.js封装了对于SharePoint列表的CRUD操作(包含同步和异步两种),以及一些工具方法 2020-06-02 lib 文件夹是平时开发中所用到的一些类库 jquery-3.1.0.min.js jquery-ui.js jquery.SPServices.min.js kendo....

    JavaScript异步执行辅助工具ocSteps.zip

    ocSteps 是一个JavaScript异步执行辅助工具,主要用于支持 Node.js 中的大量异步API以及操作,以及前端浏览器里的异步任务(例如Ajax)。如果你听说过“回调地狱”这个词,那么,__ocSteps__ 的用途就很好解释了:...

    高效查询纯真IP库lib-qqwry.zip

    callback : 回调函数 //可在此时调用查询函数infoAsync(dataPath,callback) IP库初始化的异步方法info()的异步方法; 初始化需要70毫秒,以及占用9MB左右的内存,项目资源紧张可以异步初始化。//你可以这样 qqwry....

    jscl:从Common Lisp启动的Lisp-to-Javascript编译器

    JSCL是Common Lisp to Javascript编译器,可从Common Lisp启动并从浏览器执行。 入门 您可以在线尝试演示,也可以安装JSCL npm软件包: npm install -g jscl 在jscl-repl中运行jscl-repl 。 建立 如果您想破解JSCL...

    tradingview:Binary.com的Tradingview实施

    common.js-所有commong JS函数 演示-此项目不同功能的任何演示/示例代码 图片-静态资源文件 index.html-该项目的主要起始页面。 它将重定向到适当的当前生产/ beta版本 main.css -main.html中使

    utils-pro::fire: JavaScript工具函数库

    一些常用的 JavaScript 工具函数 utils-pro 提供常用的一些工具函数和方法 引入方式 utils-pro支持script标签引入,挂载在全局的window.rook变量下。 [removed][removed] [removed] var OS = rook.deviceUtils.get...

    自然框架项目

    数据访问函数库,和数据库打交道的。 8. Nature.MetaData 元数据的管理,加载元数据到实体、缓存 9. Nature.Service 服务的基类,现在服务采用 一般处理程序(.ashx)来实现,因为这个比较简单,各种要求都比较低。...

    vs 2019 编译 libmodbus

    libmodbus库函数非常简洁,读写操作函数对于RTU和TCP完全通用,RTU和TCP切换只需要修改一行代码就可以实现无缝切换。 odbus_t *mb; int ret; //创建一个modbus-rtu对象,指定串口号,波特率,校验位,数据位,停止位...

    SML速分享博客源码 SMLSpeedSharingBlog.rar

    7)其中Common为辅助函数库 三、注意事项 1、开发工具:VS2012,数据库:SQLite,为什么要用sqlite数据库呢,因为买个空间就好了不需要额外购买数据库 2、网站前台:http://localhost:8888/Index.aspx 网站后台:...

    nestjs-typeorm-paginate:分页响应对象函数 + typeorm + nestjs 的类型

    import { Injectable } from '@nestjs/common' ; import { Repository } from 'typeorm' ; import { InjectRepository } from '@nestjs/typeorm' ; import { CatEntity } from './entities' ; import { paginate ,...

    o.backoffice:开放后台

    js/api:Web 服务的 API其他层: css:所有样式img:所有图像js:所有的 javascript 库js/common:常用函数js/util:实用函数首页: 主页.html添加新模块: module.html、module.backoffice、module.listener、...

    node-utils:javascript工具库

    JavaScript工具类库 从jQuery中整理的部分的工具函数以及平时积累的部分工具函数,方便开发使用 ###测试 npm run test 如何使用 安装 cnpm install heibao-utils --save-dev; 引用 import Utils from "heibao-utils...

    我用一天时间“偷了”网易云音乐50W+用户信息 / python爬虫

    common.py (需要用到的函数) demo.py (主程序) 四、数据 一、思路 在GitHub上已经有网易云音乐的node.js API(GitHub:https://github.com/Binaryify/NeteaseCloudMusicApi)。根据这个库提供的信息,可以很轻易...

    用于node.js和浏览器的小型、通用的函数helper库

    Unlike other well-known libraries, hu only provides a reduced but very common set of useful functions. It aims to be a lightweight and small library which can be easily embedded as a part of an ...

Global site tag (gtag.js) - Google Analytics