-1

我有以下功能:

  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)

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

请注意,我正在使用带有 vb.net 的 asp.net

4

2 回答 2

0

使用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
于 2013-10-01T07:39:59.333 回答
0

我建议您使用 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>
于 2013-10-01T07:45:47.273 回答