易截截图软件、单文件、免安装、纯绿色、仅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中最常用的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="retu ......

javascript事件详细说明

 原文网址:http://www.ccvita.com/?s=onbeforepaste
javascript事件列表解说javascript事件列表解说
事件 浏览器支持 解说
一般事件 onclick IE3、N2 鼠标点击时触发此事件
ondblclick IE4、N4 鼠标双击时触发此事件
onmousedown IE4、N4 按下鼠标时触发此事件
onmouseup IE4、N4 鼠标按下后松开鼠标时触发此事 ......

javascript动态加载Html标签

写一个小系统时,需要动态添加表单元素,按自己的实现方法写了这篇教程!
我想各位在很多网站上都看到过类似的效果!
1、先用document.createElement方法创建一个input元素!
程序代码
var newInput = document.createElement("input");
2、设定相关属性,如name,type等
程序代码
newInput.type=mytype;
newInput.name ......

JAVASCRIPT身份验证 (学习经验)

javascript 代码为:
function getName(code){
var name=xzqh[code];
if(name==null){
return name;
}
//如果不是00结尾的,则补上市名称,659000例外 429000,469000
if(code%100 != 0 && (code-code%100)!=659000 && (code-code%100)!=429000 && (code-code%100)!=469000){
var cityName= ......

深入解JavaScript函数

JavaScript函数语法
函数是进行模块化程序设计的基础,编写复杂的Ajax应用程序,必须对函数有更深入的了解。javascript中的函数不同于其他的语言,每个函 数都是作为一个对象被维护和运行的。通过函数对象的性质,可以很方便的将一个函数赋值给一个变量或者将函数作为参数传递。在继续讲述之前,先看一下函数的 使用语法: ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号