标签:
示例1:
关于事件对象
MSIE:window.event, cancelBubble, returnValue, srcElement, button(鼠标按键,1,4,2,左中右)
W3C:event, stopPropagation(), preventDefault(), target, button(鼠标按键,0,1,2,左中右)
示例2:
得到页面中某点坐标
示例代码:
function getPointInPage(eventObject) {
eventObject = eventObject || getEventObject(eventObject);
var w3cDom = document.documentElement;
return {
‘x‘: eventObject.pageX || (eventObject.clientX + w3cDom.scrollLeft) || document.body.scrollLeft,
‘y‘: eventObject.pageY || (eventObject.clientY + w3cDom.scrollTop) || doucument.body.scrollTop
};
}
示例3:
将连字符型字符串变为驼峰型字符串
示例代码:
function camelize(str) {
return str.replace(/\-(\w)/g, function (allMathches, part1) {
return part1.toUpperCase();
});
}
alert(camelize(‘s-a-ad-ee‘));
=> sAAdEe
示例4:
将驼峰型字符串变为连字符型字符串
示例代码:
function unCamelize(str) {
return str.replace(/([A-Z])/g, function (allMathes, part1) {
return ‘-‘ + part1.toLowerCase();
});
}
示例5:
得到节点类名
示例代码:
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, ‘‘);
};
function getClassName(element){
return element.className.replace(/\s+/g, ‘ ‘).trim().split(‘ ‘);
}
var arr = getClassName(document.getElementById(‘ceshi‘));
for (var i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
示例6:
判定某节点是否含有某类名
示例代码:
function hasClassName (element, className) {
if (!(element = $(element))) {
return false;
}
var classArr = getClassName();
for (var i = 0; i < classArr.length; i++) {
if (classArr[i] === className) {
return true;
}
}
return false;
}
标签:
原文地址:http://www.cnblogs.com/bugong/p/4280035.html