易截截图软件、单文件、免安装、纯绿色、仅160KB

操作ClassName的工具函数(JavaScript权威指南)

/**
* CSSClass.js
*/
var CSSClass = {}; //Create our namespace object
//Return tru if element e is a member of the class c;false otherwise
CSSClass.is = fucntion(e, c)
{
if(typeof e == "string")
e = document.getElementById(e);
//Before doing a regexp search,optimize for couple of common cases.
var classes = e.className;
if(!classes){return false;}
if(classes == c){return true;}

// Otherwise, user a regular expression to search for c as a word by itself
// \b in a regular expression requires a match at a word boundary,
return e.className.search("\\b" + c + "\\b") != -1;
};
// Add class c to the className of element e if it is not already there.
CSSClass.add = function(e, c)
{
if(typeof e == "string")
{
e = document.getElementById(e);
if(CSSClass.is(e, c))//If already amember, do nothing
{
return;
}

//Whitespace a separator, if needed
if(e.classeName)
{
c= ""+c
}
e.className = += c; //Append the new class to the end
}
};
//Remove all occurrences(if any) of class c from the className of element e
CSSClass.remove = function(e, c)
{
if(typeof e == "string")
{
e = document.getElementById(e);
}

//Search the className for all ovvurrences of c and replace with "".
// \s* matches any number of whitespace characters.
// "g" makes the regular expression match any number of occurrences.
e.className = e.className.replace(new RegExp("\\b" + c + "\\b\\s*", "g"), "");
}; 


相关文档:

javascript框架之继承机制

大一点的框架都有这个东西。Prototype原来的继承机制非常弱,为了与mootools对抗也强化了这一方面。嘛,要用原型继承来模仿类继承,都基本存在一个克隆函数。把父类的原型属性复制到子类上去。理念的东西暂时这么多,动手实践一下最实际。我们设计一个数组类,拥有原生数组的能力与新扩展的能力。

var isNumber ......

JavaScript仿Excel表格演示

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0041)/ -->
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>JavaScript仿Excel表格演示- /</TITLE>
< ......

Javascript中最常用的55个经典技巧


1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)><td>no</table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
3. onpaste="return false" 不准粘贴
4. oncopy="return false;" oncut="return ......

Javascript操作下拉框的常用方法

 function AddDropDownList(id,fatherCtl)
{
    if(!document.getElementById(id))
    {
        var ddl = document.createElement('select');
        ddl.s ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号