asp.net 中的脚本消息框
Script Message Box in asp.net
我有以下函数:
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
相关文章:
- 选项卡侦听器未被来自后台脚本的消息激活
- 如何在弹出脚本到内容脚本之间发送消息并返回
- 在加载之前从内容脚本向加载项发出消息
- 我收到消息“资源解释为脚本,但使用 MIME 类型文本/html 传输”
- 将消息从控制器传递到视图中的 AJAX 脚本
- Chrome扩展程序,如何将消息从面板发送到内容脚本
- 为什么我的附加组件面板的内容脚本在更改 contentURL 后不再响应端口消息
- JS脚本未按预期工作,没有错误消息
- chrome广播消息到内容脚本
- 是否可以使用chrome.tabs.sendmessage从内容脚本向背景页发送消息
- 使用chrome扩展,如何使用长寿命连接(端口)将消息从后台脚本传递到内容脚本
- 如何筛选重复消息的SSE脚本
- 从主脚本到内容脚本的多条消息
- 我可以使用jquery和AJAX来调用cgi-bin脚本,然后添加消息事件来处理服务器发送事件吗
- 避免“;无响应脚本"foreach循环中的消息
- 如何在Chrome扩展弹出窗口和内容脚本之间发送消息
- Chrome 打包应用 - 消息从后台传递.js传递到另一个脚本页面
- PHP密码脚本和JavaScript刷新冲突,发出我想消除的表单重新提交消息
- 阻止“停止执行此脚本”消息
- 为什么这个“正在加载”消息脚本不工作在FF?(javascript)