Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 加载弹出窗口并用单击链接中的信息填充_Javascript_Jquery_Css - Fatal编程技术网

Javascript 加载弹出窗口并用单击链接中的信息填充

Javascript 加载弹出窗口并用单击链接中的信息填充,javascript,jquery,css,Javascript,Jquery,Css,我想创建一个报告/标记评论的系统 在这一点上,我只是让它发送到一个隐藏的div和点击的“标志”链接旁边的div中的字段的commentid。(摘自:) 我在每条评论中都有类似的内容: <a class="flag" id="flag-post-@(item.ID)">flag</a> 标志 对于我的jquery: $(".flag").click(function () { var commentId = $(this).attr('id')

我想创建一个报告/标记评论的系统

在这一点上,我只是让它发送到一个隐藏的div和点击的“标志”链接旁边的div中的字段的commentid。(摘自:)

我在每条评论中都有类似的内容:

<a class="flag" id="flag-post-@(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>
$(“.flag”)。单击(函数(){
var commentId=$(this.attr('id');
$(“#注释id标签”).val(注释id);
//获取占位符元素的位置
var pos=(“#”+commentId).offset();
变量宽度=(“#”+commentId).width();
//直接在占位符上显示菜单
$(“#menu”).css({“left”:(pos.left+width)+“px”,“top”:pos.top+“px”});
$(“#菜单”).show();
});

但是它没有任何作用?

您在两个地方缺少了
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();
});

您在两处缺少
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();
});

你检查过元素的Z-索引了吗?是的,通过使用我发布的链接上的第二个答案,还有另一个问题是我已经有了id=menu的其他东西!所以这也让我头疼!。你检查过元素的Z-索引了吗?是的,通过使用我发布的链接上的第二个答案,还有另一个问题是我已经有了id=menu的其他东西!所以这也让我头疼!。