asp.net 中的脚本消息框

Script Message Box in asp.net

本文关键字:消息 脚本 net asp      更新时间:2023-09-26

我有以下函数:

  Public Function javaMsg(ByVal message As String) As String
    Dim sb As New System.Text.StringBuilder()
    sb.Append("window.onload=function(){")
    sb.Append("alert('")
    sb.Append(message)
    sb.Append("')};")
    Return sb.ToString()
End Function

这就是我调用函数的方式:

Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", x.javaMsg("Do you want to choose a date?"), True)

此警报仅显示"确定"按钮 如何添加"取消"按钮? 我如何使用单击时的每个按钮来完成某项工作?

请注意,我正在使用 asp.net 和 vb.net

我建议您使用 jQuery UI 对话框。这是目前最常用的对话框。

检查以下链接:

对话

这里有一个例子:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Dialog - Modal confirmation</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
  $(function() {
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      height:140,
      modal: true,
      buttons: {
        "Delete all items": function() {
          $( this ).dialog( "close" );
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  });
  </script>
</head>
<body>
<div id="dialog-confirm" title="Empty the recycle bin?">
  <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
<p>Sed vel diam id libero <a href="http://example.com">rutrum convallis</a>. Donec aliquet leo vel magna. Phasellus rhoncus faucibus ante. Etiam bibendum, enim faucibus aliquet rhoncus, arcu felis ultricies neque, sit amet auctor elit eros a lectus.</p>

</body>
</html>

使用 confirm 而不是 alert ...

  Public Function javaMsg(ByVal message As String) As String
    Dim sb As New System.Text.StringBuilder()
        sb.Append("window.onload=function(){");
        sb.Append("var r=confirm('");
        sb.Append(message);
        sb.Append("');");
        sb.Append("if(r==true){");
        sb.Append("alert('clicked OK');}");
        sb.Append("else{");
        sb.Append("alert('clicked CANCEL');}");
        sb.Append("};");
        return sb.ToString();
End Function