首页 > Web开发 > 详细

js获取焦点位置

时间:2014-04-10 12:57:13      阅读:625      评论:0      收藏:0      [点我收藏+]

 

 

 

function showPrompt(el) {
  var info = getHintInfo(el);
  $("#" + el.id).attr("title", info);
 }
 
 function getHintInfo(el) {
  var count = 0;
  var info = "";
  $("[name*=spendTimePercent]").each(
   function () {
    var val = parseFloat($(this).val());
    if (!isNaN(val)) {
     count += val;
    }
   }
  );
  if (count > 100) {
   info = "您填的百分比已经<font color=‘red‘>超出<b>" + (count - 100) + "%</b></font>";
  } else {
   info = "您最多还可以填写<b>" + (100 - count) + "%</b>";
  }
  
  return info;
 }
 
 function showHint(el) {
     /*var position = getPosition(el);
 
     var div = "<div class=‘shadow1‘><div class=‘shadow2‘><div class=‘shadow3‘><div class=‘container‘>"
       + getHintInfo(el) + "</div></div></div></div>";
 
     document.getElementById(‘hintDiv‘).style.display = ‘block‘;
     document.getElementById("hintDiv").innerHTML = div;
     document.getElementById(‘hintDiv‘).style.top = position[‘y‘] + el.offsetHeight + 5 + "px";
     document.getElementById(‘hintDiv‘).style.left = position[‘x‘];*/
    
     //           <!-- onmousemove="showPrompt(this)"  onblur="hideHint()" onkeyup="updateSpendTimePercent(‘${mapstatus.index}‘,‘${status.index }‘);"-->
    
    // var info = getHintInfo(el);
     $(‘#‘ + el.id).popover({
      toggle:‘popover‘,
      title:‘<font size=2><b>可填百分比</b></font>‘,
      content:getHintInfo(el),
      trigger:‘manual‘,
      html:true
     });
     $(‘#‘ + el.id).popover(‘show‘);
    
 }
 
 function hideHint(el) {
     //document.getElementById(‘hintDiv‘).style.display = ‘none‘;
      $(‘#‘ + el.id).popover(‘destroy‘);
 }
 
 function getPosition(obj) {
     var position = new Array();
     position[‘x‘] = obj.offsetLeft;
     position[‘y‘] = obj.offsetTop;
     while(obj = obj.offsetParent)
     {
         position[‘x‘] += obj.offsetLeft;
         position[‘y‘] += obj.offsetTop;
     }
     return position;
 }

js获取焦点位置,布布扣,bubuko.com

js获取焦点位置

原文:http://www.cnblogs.com/chchao/p/3654017.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!