问题
I am new to code and starting with ASP. How do I create a simple message box so I can alert the users on the web page?
回答1:
Here is one way of doing it:
<%
Dim message
message = "This is my message"
Response.Write("<script language=VBScript>MsgBox """ + message + """</script>")
%>
回答2:
<% response.write("<script language=""javascript"">alert('Hello!');</script>") %>
回答3:
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
alert("Hello!");
}
</script>
</body>
</html>
Copy Paste this in an HTML file and run in any browser , this should show an alert using javascript.
回答4:
If you want to do it from code behind, try this:
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert('Message');", true);
来源:https://stackoverflow.com/questions/956977/display-messagebox-in-asp