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字符串函数 收藏
concat
将两个或多个字符的文本组合起来,返回一个新的字符串。
var a = "hello";
var b = ",world";
var c = a.concat(b);
alert(c);
//c = "hello,world"
indexOf
返回字符串中一个子串第一处出现的索引(从左到右搜索)。如果没有匹配项,返回 -1 。
var index1 = a.indexOf ......
返回一个给定id属性值的元素节点的对象
document.getElememtById(id)
返回一个包含所有给定标签的元素的数组
document.getElementsByName(tag)
获取元素属性
document.getAttribute(attribute)
设置元素属性值
document.setAttribute(attribute)
......
最近遇到个问题,开发web项目的时候,可能flex只用来实现项目的部分模块。当flex需要在客户端写入/读取一些状态信息的时候,我们会想到用cookie。flex是不支持cookie的,只有SharedObject这个本地对象。所以解决的办法就有两个:
flex通过调用js来实现对cookie的操作;
js通过flex实现对SharedObject的操作;
这两种方法 ......
function keyDown(){
//屏蔽鼠标右键、Ctrl+n、shift+F10、F5刷新、退格键
//alert("ASCII代码是:"+event.keyCode);
if ((window.event.altKey)&&
((window.event.keyCode==37)|| //屏蔽 Alt+ 方向键 ←
(w ......