我如何使用ScriptManager多个函数
本文关键字:函数 ScriptManager 何使用 | 更新日期: 2023-09-27 18:08:11
if (mod != 1)
{
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "Funcm()", true);
}
if (ven != 1)
{
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "Funcv()", true);
}
if (loc != 1)
{
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "Funcl()", true);
}
if (st != 1)
{
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "Funcst()", true);
}
只有第一个"if"工作并隐藏项目,但其他不工作,我该如何解决这个问题?
function Funcm() { document.getElementById("ModelMenu").style.display = "none";}
function Funcv() { document.getElementById("VendorMenu").style.display = "none";}
function Funcl() { document.getElementById("LocMenu").style.display = "none";}
function Funcst() { document.getElementById("StatusMenu").style.display = "none";}
然后尝试这样做,即只注册一个脚本…
string myScript = string.Empty;
if (mod != 1)
{
myScript += "document.getElementById('"ModelMenu'").style.display = '"none'";";
}
if (ven != 1)
{
myScript += "document.getElementById('"VendorMenu'").style.display = '"none'";";
}
if (loc != 1)
{
myScript += "document.getElementById('"LocMenu'").style.display = '"none'";";
}
if (st != 1)
{
myScript += "document.getElementById('"StatusMenu'").style.display = '"none'";";
}
if (!string.IsNullOrEmpty(myScript))
{
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "myScript", myScript, true);
}
或者如果你的函数是预定义的,你必须使用它们:
string myScript = string.Empty;
if (mod != 1)
{
myScript += "Funcm();";
}
if (ven != 1)
{
myScript += "Funcv();";
}
if (loc != 1)
{
myScript += "Funcl();";
}
if (st != 1)
{
myScript += "Funcst();";
}
if (!string.IsNullOrEmpty(myScript))
{
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "myScript", myScript, true);
}