出现某些情况时显示警报错误消息

时间:2019-11-22 08:06:30

标签: javascript c# html asp.net twitter-bootstrap

我在页面加载时有以下代码,用于显示错误警报:

//Currently the output from displaying a "law" on my website is this:
//The &plusmn and the second number (sd - in the code below SDBefore) is formatted green for 0<=sd  <50. 
//The first number (mean - in the code before meanBefore) is not formatted. 
//AFAIK the javascript file on the server produces this is currently as follows:

$(".mean-value").html("Loading");
     $(".sd-value").html("Loading");


            //parse the returned data
            var jsonData = JSON.parse(data);

            $(".mean-value").html(parseInt(jsonData.mean));
            $(".sd-value").html("&plusmn; " + parseInt(jsonData.sd));

                currentHTML = currentHTML + "<td><a href='./event-profile.php?id=" + event.event_id + "' >" + event.event_name + "</a></td>";

                if(event.SDBefore >= 0 && event.SDBefore < 50)
                {
                    currentHTML = currentHTML + "<td>" + event.meanBefore + "<span class='sd-value-green'>&plusmn" + event.SDBefore + "</span></td>";
                 }
                 
//.....( JSON is a format for storing and transporting data).

//So what I want to do is one of the following a) or b)

// a) format the mean only according to 0<=sd  <50.  
 
Is this correct?

           //parse the returned data
            var jsonData = JSON.parse(data);
             $(".mean-value").html(parseInt(jsonData.mean));
            //$(".sd-value").html("&plusmn; " + parseInt(jsonData.sd)); //Don't need this line

currentHTML = currentHTML + "<td><a href='./event-profile.php?id=" + event.event_id + "' >" + event.event_name + "</a></td>";

                if(event.SDBefore >= 0 && event.SDBefore < 50)
                {
                    currentHTML = currentHTML + "<td>" +          "<span class='mean-value-green'>event.meanBefore+</span>" + &plusmn + event.SDBefore + "</td>";
                    }
                    
//b) format the whole law according to 0<=sd  <50.  
  
//So I have added the following (in bold):
// Is this correct?

$(".mean-value").html("Loading");
     $(".sd-value").html("Loading");
       $(".law-value").html("Loading");

            //parse the returned data
            var jsonData = JSON.parse(data);

  $(".mean-value").html(parseInt(jsonData.mean));
  $(".sd-value").html("&plusmn; " + parseInt(jsonData.sd))
 $(".law-value").html(parseInt(jsonData.mean) + "&plusmn; " + parseInt(jsonData.sd));

currentHTML = currentHTML + "<td><a href='./event-profile.php?id=" + event.event_id + "' >" + event.event_name + "</a></td>";

                if(event.SDBefore >= 0 && event.SDBefore < 50)

                {
             currentHTML = currentHTML + "<td>" + "<span class='law-value-green'> event.meanBefore + &plusmn + event.SDBefore" + "</span></td>";

这是调用错误的地方。页面重新加载并显示错误。

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["message"] == "noemployees")
                    AlertDanger.Visible = true;

我有以下标记

if (payFitments == null)
{
     Response.Redirect("Default?message=noemployees");
}

如何显示此消息而不必再次加载默认页面?在网络上看不到能清楚显示这一点的示例。

3 个答案:

答案 0 :(得分:2)

您正在使用JQuery remove,它可以从DOM中有效删除警报。因此,无法在不重新加载页面的情况下再次显示它。

但是您可以改用JQuery detach。然后,您可以使用appendTo重新插入。

var alert = null;

function showHideAlert() {
    if (alert) {
        alert.appendTo("body");
        alert = null;
    } else {
        alert = $(".alert").detach();
    }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<body>
    <button onclick="showHideAlert();">Show/Hide alert</button>
    <div class="alert">ALERT!!!</div>
</body>

答案 1 :(得分:0)

尝试提供静态html文件,然后使用Javascript中的警报功能。您可以了解到here。按下按钮的示例:

<html>

<head>
  <script>
    function onError() {
      try {
        ...
      } catch (...) {

        var error
        error = "button was pressed"
        alert(error)
      }
    }
  </script>
</head>

<body>
  <button id="myButton" onClick="onError()">do not click</button>
</body>

</html>

答案 2 :(得分:-1)

    public static void Main(string[] args) {
      var summary = BenchmarkRunner.Run(typeof(Program).Assembly,
        DefaultConfig.Instance
          .With(Job.Default.WithCustomBuildConfiguration("Baseline"))
          .With(Job.Default.WithCustomBuildConfiguration("Current")));
    }

注意:-我想您已经错过了这个……将您的jQuery代码放在您的body标签中……