2011-01-08 62 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(); 
}); 
相關問題