【发布时间】:2015-05-15 11:24:40
【问题描述】:
我需要一个 Javascript 或 jquery 在我的 C# 代码隐藏中 如果我将它放在 div 中,我会像它应该的那样工作。但现在我想把脚本放在 if else 里面
查看id为chart2的部分
<div style="position: absolute; top: 0; left: 0; height: 100%; width: 100%; z-index:0; ">
<asp:Literal ID="ltrRenderChart" runat="server"></asp:Literal>
</div>
<div ID="chart2"style="position: absolute; top: 0; left: 50%; height: 100%; width: 100%; z-index:-1">
<script>$("#chart2").css("z-index",0);</script>
<asp:Literal ID="ltrRenderChart2" runat="server"></asp:Literal>
</div>
<div style="position: absolute; top: 50%; left: 0; height: 100%; width: 100%; z-index:-1;">
<asp:Literal ID="ltrRenderChart3" runat="server"></asp:Literal>
</div>
<div style="position: absolute; top: 50%; left: 50%; height: 100%; width: 100%; z-index:-1;">
<asp:Literal ID="ltrRenderChart4" runat="server"></asp:Literal>
</div>
</div>
但是如果我把它写在 if-else 里面它不会影响任何东西。
else if (n == 2 && chart.Width == "50%")
{
literal = ltrRenderChart2;
string script = "<script>$(\"#chart2\").css(\"z-index\",0);</script>";
ScriptManager.RegisterClientScriptBlock(ltrRenderChart2, ltrRenderChart2.GetType(), "Script", script,false);
}
else if (n == 2 && chart.Height == "50%")
{
literal = ltrRenderChart2;
string str = "<script>$(\"#chart2\").css(\"z-index\",0);</script>";
ScriptManager.RegisterClientScriptBlock(ltrRenderChart2, ltrRenderChart2.GetType(), "Script", str, false);
}
有人知道这个问题吗?
谢谢
【问题讨论】:
-
你的页面中加载了 jQuery 吗?
-
这里的
chart是什么? -
小心
<script>标签!我记得,Visual Studio 在 ascx 和 aspx 文件中存在一些重大问题,因为它将其解析为服务器端脚本标记!我记得有时我们不得不像这样拆分它:"<scr" + "ipt>"。在我第一次遇到这种行为之前,我简直不敢相信...... -
@Markus
标签: javascript c# jquery z-index scriptmanager