【问题标题】:bootbox.alert not working from code behindbootbox.alert 不能从后面的代码中工作
【发布时间】:2017-08-04 21:11:11
【问题描述】:

我正在使用引导文件上传器将数据从 excel 导入数据库。数据导入后,我需要向用户显示一条消息。所以我有以下代码

        string strScript = "bootbox.alert('" + Resources.Resource.Success_SaveUserInfo + "');";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "UserSave", strScript, true);

但它不起作用。页面冻结而不是警报。但是如果我使用下面的代码,它就可以工作。

  string strScript = "alert('" + Resources.Resource.Success_SaveUserInfo + "');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "UserSave", strScript, true);

我已经添加了 bootbox.min.js。所以这不是问题。

【问题讨论】:

    标签: javascript c# twitter-bootstrap cross-browser


    【解决方案1】:

    你可以这样做

    string strScript = "<script type = 'text/javascript'>bootbox.alert('" + Resources.Resource.Success_SaveUserInfo + "');</script>";
    Page.ClientScript.RegisterStartupScript(this.GetType(), "UserSave", strScript, true);
    

    或

    强烈推荐调用 javascript 函数,也可以重复使用

    Page.ClientScript.RegisterStartupScript(this.GetType(), "UserSave", CustomalertFunction('" + Resources.Resource.Success_SaveUserInfo + "'), true);
    

    并编写一个javascript函数

    function CustomalertFunction(message)
    {
      bootbox.alert(message);
    }
    

    【讨论】:

    • 已经尝试在上面的代码中不起作用。但奇怪的是,如果我修改 bootbox.alert(message);简单的警报就是工作
    • Ohkk 现在你要做的就是在document.ready 上添加bootbox.alert() 并检查它是否有效,如果没有检查你是否添加了与引导箱相关的脚本,你的页面中似乎缺少脚本让我知道它是否有效
    • 哦,我知道你已经提到你已经添加了 bootbox.min.js 请确保你已经添加了相关的 css 以及 bootbox.css 和 jquery min js 也在页面中的 所有js的顶部
    猜你喜欢
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    • 1970-01-01
    • 2017-02-07
    • 1970-01-01
    相关资源
    最近更新 更多