警报并确认JavaScript中的MessageBox [英] alert and confirm MessageBox in javascript
问题描述
嗨
我想在单击窗体上的保存"按钮(保存程序")后显示一个警报消息框",然后在警报消息框"上单击确定"后,我要调用确认消息框",然后单击确定"后,它应该显示为另一种形式(添加阶段" ),但是如果我单击取消",则应回到保存程序"表单.
这是我的JavaScript函数(aspx代码)
Hi
I want to display an Alert MessageBox after I clicked save button on the form(Save Program), then after I clicked OK on the Alert MessageBox I want to call Confirmatiom MessageBox, then when I clicked OK it should take to another form(Add Phase) but if I clicked Cancel it should take me back to Save Program form.
Here is my javascript function(aspx code)
function display()
{
alert("Program Has Been Successfully Create");
if (confirm("Do you want to create phases?") == true)
{
window.location = "CreateProgramPhase.aspx";
}
else
{
window.location = "CreateProgram.aspx";
}
return false;
}
还有我的保存按钮(cs代码)
And my save button(cs code)
protected void btnSave_Click(object sender, EventArgs e)
{
AddProgram();
btnSave.Attributes.Add("onClick", "return display();");
}
在确认消息框中单击确定"后,我无法显示CreateProgramPhase表单.
谢谢
I can''t display CreateProgramPhase Form after I clicked OK in the Confirmatiom MessageBox.
Thanks
推荐答案
尝试以下javascript函数
try below javascript function
function display()
{
alert("Program Has Been Successfully Create");
if (confirm("Do you want to create phases?") == true)
{
window.location = "CreateProgramPhase.aspx";
}
else
{
window.location = "CreateProgram.aspx";
}
return true;
}
更改您的JavaScript
Change your javascript
function display() {
alert("Program Has Been Successfully Create");
if (confirm("Do you want to create phases?") == true) {
window.location = "CreateProgramPhase.aspx";
}
else {
window.location = "CreateProgram.aspx";
}
}
</script>
并将按钮单击事件更改为
and change button click event as
protected void btnSave_Click(object sender, EventArgs e)
{
AddProgram();
if (ClientScript.IsClientScriptBlockRegistered("test1212") == false)
ClientScript.RegisterStartupScript(this.GetType(), "test1212", "<script>display();</script>");
}
使用调试器尝试以下代码
function display()
{
debugger;
alert("Program Has Successfully Create");
if (confirm("Do you want to create phases?"))
{
window.location = "CreateProgramPhase.aspx";
}
else
{
window.location = "CreateProgram.aspx";
}
return true;
}
阅读以下链接以了解调试技术
http://sixrevisions.com/javascript/javascript-debugging-techniques-in-ie-6/ [ ^ ]
Read following link for debugging technique
http://sixrevisions.com/javascript/javascript-debugging-techniques-in-ie-6/[^]
button.Attributes.Add("onclick", "javascript:display()")
这篇关于警报并确认JavaScript中的MessageBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!