运行 javascript 按下按钮 ASP.NET
Run javascript on button press ASP.NET
我想调用 javascript 函数以防我后面的代码中发生某些事情。
如果它像下面的代码一样,它在回发警报 windows 显示并正确显示后工作正常。但是如果我从 else 块中删除评论 none else 块中的那两个脚本会发生什么?
我可以从代码隐藏中执行多少这些操作是否有任何限制?
if (condition) {
if (condition2) {
var message = "It happened !";
Page.ClientScript.RegisterStartupScript(this.GetType(), "yep1", "alert('" + message + "')", true);
}
} else {
var msg = "It does not work like that";
Page.ClientScript.RegisterStartupScript(this.GetType(), "nope1", "alert('" + msg + "!')", true);
//Page.ClientScript.RegisterStartupScript(this.GetType(), "nope2", "alert('" + msg + "')", true);
}
这样就可以了。正如函数名所说,它注册了启动脚本,所以你要更改它而不是插入 2。这样它就可以同时执行 ^^
if (condition)
{
if (condition2)
{
var message = "It happened !";
Page.ClientScript.RegisterStartupScript(this.GetType(), "yep1", "alert('"+message+"');", true);
}
}
else
{
var msg = "It does not work like that";
Page.ClientScript.RegisterStartupScript(this.GetType(), "nope1", "alert('"+msg+"!'); alert('" + msg + "');", true);
//Page.ClientScript.RegisterStartupScript(this.GetType(), "nope1", "alert('"+msg+"!')", true);
//Page.ClientScript.RegisterStartupScript(this.GetType(), "nope2", "alert('" + msg + "')", true);
}
我想调用 javascript 函数以防我后面的代码中发生某些事情。
如果它像下面的代码一样,它在回发警报 windows 显示并正确显示后工作正常。但是如果我从 else 块中删除评论 none else 块中的那两个脚本会发生什么?
我可以从代码隐藏中执行多少这些操作是否有任何限制?
if (condition) {
if (condition2) {
var message = "It happened !";
Page.ClientScript.RegisterStartupScript(this.GetType(), "yep1", "alert('" + message + "')", true);
}
} else {
var msg = "It does not work like that";
Page.ClientScript.RegisterStartupScript(this.GetType(), "nope1", "alert('" + msg + "!')", true);
//Page.ClientScript.RegisterStartupScript(this.GetType(), "nope2", "alert('" + msg + "')", true);
}
这样就可以了。正如函数名所说,它注册了启动脚本,所以你要更改它而不是插入 2。这样它就可以同时执行 ^^
if (condition)
{
if (condition2)
{
var message = "It happened !";
Page.ClientScript.RegisterStartupScript(this.GetType(), "yep1", "alert('"+message+"');", true);
}
}
else
{
var msg = "It does not work like that";
Page.ClientScript.RegisterStartupScript(this.GetType(), "nope1", "alert('"+msg+"!'); alert('" + msg + "');", true);
//Page.ClientScript.RegisterStartupScript(this.GetType(), "nope1", "alert('"+msg+"!')", true);
//Page.ClientScript.RegisterStartupScript(this.GetType(), "nope2", "alert('" + msg + "')", true);
}