一些有用的JavaScript函数(3)
发表评论»获取页面窗口大小
function getPageSize(){
var size = [];
size.push(window.innerWidth || document.documentElement.clientWidth);
size.push(window.innerHeight || document.documentElement.clientHeight);
return size;
}
获取鼠标坐标
function getMousePosition(e){
var p = [];
e = e || window.event;
p.push(e.clientX);
p.push(e.clientY);
return p;
}
阻止事件冒泡
function stopBubble(e){
if(e&&e.stopPropagation){
e.stopPropagation();
}else{
window.event.cancelBubble = true;
}
}
阻止浏览器默认动作
function stopDefault(e){
if (e&&e.preventDefault){
e.preventDefault();
}
else{
window.event.returnValue = false;
}
return false;
}
获取json长度
function getJsonLength(jsonData){
var jsonLength = 0;
for(var item in jsonData) jsonLength++;
return jsonLength;
}
其实都是些很简单的函数,记录下来,减少重复操作,提高效率!
暂时还没有评论