2011-01-08 140 views
1

我想创建一个报告/标记注释的系统。加载弹出窗口并用点击链接填充信息

在这一点我只是得到它发送纪念到一个隐藏的div内的字段和点击“标志”链接旁边的弹出窗口。 (摘自:How to position one element relative to another with jQuery?

我有这样的事情沿着每个评论:

<a class="flag" id="[email protected](item.ID)">flag</a> 

,这对我的jquery:

$(".flag").click(function() { 

      var commentId = $(this).attr('id'); 
      $("#comment-id-label").val(commentId); 


      //get the position of the placeholder element 
      var pos = ("#"+commentId).offset(); 
      var width = ("#"+commentId).width(); 
      //show the menu directly over the placeholder 
      $("#menu").css({ "left": (pos.left + width) + "px", "top": pos.top + "px" }); 
      $("#menu").show(); 
     }); 

<div style="position: absolute; display: none;" id="menu"> 
      <input id="comment-id-label" type="text" value="" /> 
</div> 

,但它不工作的任何想法?

+0

你检查Z-INDEX元素? – Nazariy 2011-01-08 18:15:48

回答

1

您在两个地方错过了jQuery别名$

我做了一些调整,并得到了这个工作:

$(".flag").click(function() { 

    var commentId = $(this).attr('id'), 
     comment = $("#"+commentId); 

    $("#comment-id-label").val(commentId); 

    //get the position of the placeholder element 
    var pos = comment.offset(); 
    var width = comment.width(); 

    //show the menu directly over the placeholder 
    $("#menu").css({ 
     "left": pos.left+width, 
     "top": pos.top 
    }).show(); 
}); 
相关问题