/*得到页面中某个元素的位置的函数 */
function getposition(obj) { var r = new Array(); r['x'] = obj.offsetLeft; r['y'] = obj.offsetTop; while(obj = obj.offsetParent) { r['x'] += obj.offsetLeft; r['y'] += obj.offsetTop; } return r; }
//得到字符串长度 function getLen( str) { var totallength=0; for (var i=0;i<str.length;i++) { var intCode=str.charCodeAt(i); if (intCode>=0&&intCode<=128) { totallength=totallength+1; //非中文单个字符长度加 1 } else { totallength=totallength+2; //中文字符长度则加 2 } } return totallength; }
//取消元素冒泡的函数 function cancelbubble(obj) { //<textarea style="width:400px"></textarea> //var log = document.getElementsByTagName('textarea')[0]; var all = obj.getElementsByTagName('*'); for (var i = 0 ; i < all.length; i++) { //log.value += all[i].nodeName +":" +all[i].id + "/r/n"; all[i].onmouseover = function(e) { if (e) //停止事件冒泡 e.stopPropagation(); else window.event.cancelBubble = true; obj.style.display='block'; //this.style.border = '1px solid white'; //log.value = '鼠标现在进入的是: ' + this.nodeName + "_" + this.id; }; all[i].onmouseout = function(e) { if (e) //停止事件冒泡 e.stopPropagation(); else window.event.cancelBubble = true; if(this.nodeName == "DIV") { obj.style.display='none'; } // else // { // obj.style.display='none'; // } //this.style.border = '1px solid white'; //log.value = '鼠标现在离开的是:' + this.nodeName + "_" + this.id; }; } }