邮件附加在alertdialog框中

时间:2018-03-22 06:07:04

标签: javascript jquery

我有一个带有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;
}

sample images

4 个答案:

答案 0 :(得分:1)

您正在使用旧消息附加消息。这就是它发生的原因。可以使用html而不是追加,而不是它可以使用。

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

答案 1 :(得分:0)

您正在附加消息,这是原因 使用

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

而不是

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

答案 2 :(得分:0)

因为您使用append

append会将旧内容与新内容合并

所以请使用html代替append

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

答案 3 :(得分:0)

您正在使用基于documentation

的jquery追加内容
  

.append()和.appendTo()方法执行相同的任务。专业   差异在于语法特定,在放置中   内容和目标。使用.append(),前面的选择器表达式   该方法是插入内容的容器。

不应使用append,而应使用像这样的html注入器。

$("#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/>");

干杯