javascript StyleSheet样式操作类
早上在csdn上看有人问页面style sheet怎么修改里面的rule,就写了个类,该类对兼容FF和IE做了处理。
/**//*--------------------------------------------
描述 : 添加新的样式rule
参数 : styleSheets索引
代码 : var ss = new styleSheet(0);
--------------------------------------------*/
var styleSheet = function(n)
...{
var ss;
if (typeof n == "number") ss = document.styleSheets[n];
this.sheet = ss;
this.rules = ss.cssRules?ss.cssRules:ss.rules;
};
/**//*--------------------------------------------
描述 : 查找样式rule,成功返回index,否则返回-1
参数 : n为rule名称
代码 : var ss = new styleSheet(0);
ss.indexOf("className")
--------------------------------------------*/
styleSheet.prototype.indexOf = function(selector)
...{
for(var i=0;i<this.rules.length;i++)
...{
if(this.rules[i].selectorText==selector)
...{
return i;
}
}
return -1;
};
/**//*--------------------------------------------
描述 : 删除样式rule
参数 : n为rule索引或者名称
代码 : var ss = new styleSheet(0);
ss.rem
相关文档:
JavaScript中的模块和名字空间是不可区分的内容。
我们定义的每个单独的函数都是作为全局对象的一个属性。而JavaScript代码模块所必须遵循的最重要的规则就是:避免定义全局变量。因为,当定义一个全局变量时,都要被其他模块覆盖的危险,所以模块化编码要用如下方式:
var ModuleClass={};
ModuleClass.函数名1=functio ......
预定时间之后执行函数
setTimeout("functionname",interval)
提取字符串中数值信息
parseInt(string)
复制节点(是否复制子节点)
cloneNode(true/false)
删除子节点
removeChild()
替换节点
replaceChild(newChild,oldChild)
子节点判断
hasChildNodes ......
返回一个给定id属性值的元素节点的对象
document.getElememtById(id)
返回一个包含所有给定标签的元素的数组
document.getElementsByName(tag)
获取元素属性
document.getAttribute(attribute)
设置元素属性值
document.setAttribute(attribute)
......
1、rcbdyctl
view plaincopy to clipboardprint?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<title>JS获取客户端IP</title>
</head>
<b ......