我在 ASPX 页面中有这段 JavaScript 代码
<script>
function show_modal(statut)
{
if (statut == true)
{
$(function ()
{
$('#modal_success').modal('show')
})
}
else
{
$(function ()
{
$('#modal_fail').modal('show')
})
}
}
</script>
这显示了一个模式弹出窗口,我喜欢从后面的代码启动它。
我尝试了这个,但没有成功:
if (resultat)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "show_modal(true);");
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "show_modal(false);");
}
但我不明白为什么!
最佳答案
This call要求您将调用包装在 <script>
中标签(或使用other overload,它允许您指定是否添加脚本标签)
ClientScript.RegisterStartupScript(this.GetType(), "",
"<script>show_modal(true);</script>");
或
ClientScript.RegisterStartupScript(this.GetType(), "",
"show_modal(true);", true);
关于c# - 从代码隐藏中调用 JavaScript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13763100/