gpt4 book ai didi

javascript - 从 C# 调用 JS 函数不起作用

转载 作者:行者123 更新时间:2023-11-28 19:13:41 24 4
gpt4 key购买 nike

下午,

我之前已经能够从我的 C# 中调用 JavaScript 函数,而且效果很好。由于某种原因,这次当我对代码进行断点时,该函数没有被命中。

这就是我的 C# 方法。

    public void tester()
{
string returnResult = HttpContext.Current.Session["result"].ToString();

Page.ClientScript.RegisterStartupScript(this.GetType(), "alerify", "alerify('" + returnResult + "');", true);
//ScriptManager.RegisterStartupScript(this, this.GetType(), "alerify", "alerify(" + returnResult + ");", true);
}

你可以看到我已经尝试了不同的方法,但该功能仍然没有得到满足。

这是我要调用的 JavaScript 函数。

    function alerify(e) {
alert(e);
if (e == "InvalidDates") {
alertify.error("gfgsdggfsdgfsdfd");
}
}

我想我错过了一些东西,但我就是不知道是什么。

最佳答案

由于它是一个字符串值,因此需要撇号(或引号)作为 JavaScript 代码中的字符串文字:

... "alerify('" + returnResult + "');" ...

关于javascript - 从 C# 调用 JS 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30303516/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com