易截截图软件、单文件、免安装、纯绿色、仅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 正则表达式

 JS的正则表达式
//校验是否全由数字组成
function isDigit(s)
{
var patrn=/^[0-9]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
//校验登录名:只能输入5-20个以字母开头、可带数字、“_”、“.”的字串
Java代码
function isRegisterUserName(s)  &n ......

javascript window.close() 去掉那讨厌的确认对话框

 <html>
    <head>
        <script type="text/javascript">
            function goHome(){
          ......

[从jQuery看JavaScript]

jQuery片段:
var
// Will speed up references to window, and allows munging its name.
window = this,
// Will speed up references to undefined, and allows munging its name.
undefined,
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,
// Map over the $ in case of overwrit ......

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="re ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号