Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.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 附加的Div工作不正常_Javascript_Asp.net Mvc - Fatal编程技术网

Javascript 附加的Div工作不正常

Javascript 附加的Div工作不正常,javascript,asp.net-mvc,Javascript,Asp.net Mvc,我正在开发MVC3应用程序并使用razor语法 在这个应用程序中,我提供了评论功能 当用户单击AddComment按钮时,它将保存在DB中,并附加在当前Div中 请检查图像 这是添加新注释之前的图像 此图像是在添加新注释后生成的 现在,我的问题是,当用户点击新添加的评论的删除按钮,我想显示消息-“删除过程从这里开始…”,但它现在工作 这是我的密码 <script src="../../Scripts/jquery.validate.min.js" type="text/javascri

我正在开发MVC3应用程序并使用razor语法

在这个应用程序中,我提供了评论功能

当用户单击AddComment按钮时,它将保存在DB中,并附加在当前Div中

请检查图像

这是添加新注释之前的图像

此图像是在添加新注释后生成的

现在,我的问题是,当用户点击新添加的评论的删除按钮,我想显示消息-“删除过程从这里开始…”,但它现在工作

这是我的密码

<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>

@model  IEnumerable<CRMEntities.Comment>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>



//Button which Saves currently added comment in DB as well display on screen...
<script src="../../Scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#AddCommentButton').click(function () 

        {     

       // alert("clicked");
            $.ajax({

                type: 'post',
                url: '/Comment/SaveComments',
                dataType: 'json',
                data:
                { 

                 'comments' : $('#Comment').val(), 
                 'EType' : @Html.Raw(Json.Encode(ViewBag.EType)), 
                  'EId' : @Html.Raw(Json.Encode(ViewBag.EId))

                },
                success: function (data) {

                    $("p.p12").append('<div style="background-color:#FAFAFA;">Recently Added... <br /><a href="@Url.Action("Details", "Employee", new { id = "__id__" })'.replace('__id__', data.OwnerID) + '">' + data.OwnerName + '</a>'+ data.cmtDateTime +'<button type="button" id=' + data.Id  + ' class="deleteComment">Delete</button></span><br />' + data.msg + '</div>')


                }

            });
        });
    });
</script>




</head>
<body>

@{



     <div class="ParentBlock">


    @foreach (var item in Model)
    {
        <div class="OwnerClass" id="OwnerName">


         <span class="EmpName"> @Html.ActionLink(item.Owner.FullName, "Details", "EMployee", new { id = item.OwnerId }, new { @style = "color:#1A6690;" })</span>

           @Html.DisplayFor(ModelItem => item.CommentDateTime)

          <span class="EmpName"><button type="button" id = "@item.Id" class="deleteComment">Delete</button></span>



        <p class="CommentP">
           @Html.DisplayFor(ModelItem => item.CommentText)
        </p>


        </div>


    }


     <p class="p12">

      </p>



</div>

      <p id="ClassPara" class="ShowComments" onclick="chkToggle()">Show All Comments</p>

}



   @Html.TextArea("Comment", "", 5, 80, "asdsd")


    <input type="button" value="Add Comment" id="AddCommentButton"/>                         
    <input type="button" value="Clear" onclick="clearText()"/>                    

    <br />







</body>
</html>





<script src="../../Scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript">


//   Working code - Deletes the comment from DB and removes hide the current Div
////////////////////////////////////////////////////////

    $(document).ready(function () {
        $(".deleteComment").click(function ()
         {
            alert("Delete process start here...");

         });
    });



</script>

@模型IEnumerable
//按钮,将当前添加的注释保存在数据库中,并显示在屏幕上。。。
$(文档).ready(函数(){
$('#AddCommentButton')。单击(函数()
{     
//警报(“点击”);
$.ajax({
键入:“post”,
url:“/Comment/SaveComments”,
数据类型:“json”,
数据:
{ 
'comments':$('#Comment').val(),
'EType':@Html.Raw(Json.Encode(ViewBag.EType)),
'EId':@Html.Raw(Json.Encode(ViewBag.EId))
},
成功:功能(数据){
$(“p.p12”).append('最近添加的…
'+data.cmtDateTime+'Delete
'+data.msg+'') } }); }); }); @{ @foreach(模型中的var项目) { @ActionLink(item.Owner.FullName,“详细信息”,“员工”,新的{id=item.OwnerId},新的{@style=“color:#1A6690;”) @DisplayFor(ModelItem=>item.CommentDateTime) 删除

@DisplayFor(ModelItem=>item.CommentText)

}

显示所有注释

} @TextArea(“Comment”,5,80,“asdsd”)
//工作代码-从数据库中删除注释并删除和隐藏当前Div //////////////////////////////////////////////////////// $(文档).ready(函数(){ $(“.deleteComment”)。单击(函数() { 警报(“删除流程从此处开始…”); }); });
使用JQuery
[on][1]
而不是
单击
;前者将在文档修改时动态处理事件,而后者在调用事件时连接事件一次

$("body").on("click", ".deleteComment", function ()
     {
        alert("Delete process start here...");
     });
$(“body”)。在(“单击”,“删除注释”,函数(){alert(“删除过程从这里开始…””);
});我已经试过了,但不起作用。。。