Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.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 - Fatal编程技术网

Javascript “警报”对话框中的消息追加

Javascript “警报”对话框中的消息追加,javascript,jquery,Javascript,Jquery,我有一个带有linkbutton和ok按钮的alertdialog对话框。 生成错误时,消息将显示在alertdialog(警报)对话框中。 但是,当生成新错误时,新消息将附加旧消息,链接按钮也将重复。 我想删除旧邮件,只显示新邮件 下面是代码片段 function AlertDialog(msg) { var newMsg=msg; if(msg==="SessionTimeOut") newMsg="@Resources.com

我有一个带有linkbutton和ok按钮的alertdialog对话框。 生成错误时,消息将显示在alertdialog(警报)对话框中。 但是,当生成新错误时,新消息将附加旧消息,链接按钮也将重复。 我想删除旧邮件,只显示新邮件

下面是代码片段

    function AlertDialog(msg) {
        var newMsg=msg;
        if(msg==="SessionTimeOut")
            newMsg="@Resources.commonResources.SessionTimeOut";

        $("#dialog-showMsg").text=" ";
        $("#dialog-showMsg #sp").append(newMsg,"<br/>","<br/>")
        $("#dialog-showMsg").dialog(
            open: function(event, ui){
            $('<a />', {
                'class': 'linkClass',
                text: 'Details',
                href: '#'
            })
            .appendTo($(".ui-dialog-content"))          //use buttonpane to display link at bottom     content
            .click(function(){
                $(event.target).dialog('close');
            });
    },
               position:{my: "center", at: "center"},
               draggable: true,
               height: 300,
               width: 260,
               show: { effect: "Fold" },
               hide: { effect: "Fold" },
               modal: true,
               buttons: {
                  OK: function() {
                  if(msg==="SessionTimeOut")
                  {window.location.href=" /" + "@AppName";}
                  $(this).dialog("close");}
               },

           });
           return true;
}

您正在用旧邮件追加邮件。这就是它发生的原因。您可以使用html而不是append,这样就可以了

$("#dialog-showMsg #sp").html(newMsg,"<br/>","<br/>")

您正在添加作为原因的消息 使用

而不是

因为你使用append

append将旧内容与新内容合并

因此,请使用html,而不是像追加一样


您正在使用jquery附加内容,基于

.append和.appendTo方法执行相同的任务。少校 区别在于语法,特别是 内容和目标。在.append中,前面的选择器表达式 方法是插入内容的容器

您应该像这样使用html注入器,而不是使用append

$("#dialog-showMsg").text=" ";
$("#dialog-showMsg #sp").html("<br/>"+newMsg+"<br/>");
或者,如果你不想使用html,你可以像这样先删除内容

$("#dialog-showMsg").text=" ";
$("#dialog-showMsg #sp").empty();
$("#dialog-showMsg #sp").append(newMsg,"<br/>","<br/>");
干杯

$("#dialog-showMsg #sp").html(newMsg,"<br/>","<br/>")
$("#dialog-showMsg").text=" ";
$("#dialog-showMsg #sp").html("<br/>"+newMsg+"<br/>");
$("#dialog-showMsg").text=" ";
$("#dialog-showMsg #sp").empty();
$("#dialog-showMsg #sp").append(newMsg,"<br/>","<br/>");