<javascript学习笔记> 设置和获取dom的css样式 、获取url参数
在项目里看到的发现不错,怕忘记留做笔记。
/**设置或获取CSS样式
*设置:css(obj,{display:'block',color:'red'});
*获取:css(obj,'color');
*/
function css() {
var obj = arguments[0], options = arguments[1]; //获得函数的参数,第一个参数是dom对象。
if(!!obj == false || typeof options == 'undefined')
return null;
if( typeof options == 'string')
return document.defaultView.getComputedStyle(obj,null)[options];
if( typeof options == 'object') {
for(var i in options) {
obj.style[i] = options[i]; //设置css样式
}
}
};
/**
* 获得url相应参数的值
* @param __name url 参数名
*/
function getUrlArgs(__name) {
var tmp = window.location.search.substr(1).match(new RegExp("(^|&)" + __name + "=([^&]*)(&|$)", "i"));
return tmp ? decodeURIComponent(tmp[2]) : null;
};

浙公网安备 33010602011771号