C#后台调用前台js封装方法

其他不多说,直接上例子,我引用的是layer弹框的移动端插件

一、页面<head>调用下面方法

<script src="/js/layer.js"></script>
    <script>
        function alertFn(msg) {
            layer.open({
                content: msg ,
                shadeClose: false,
                btn: ['OK'],
                yes: function () {
                    location.href = "default.aspx?i=" + Math.random();
                },
            });
        }
</script>
//页面必须要有form
<form runat="server">

</form>

二、后台调用方法

 ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alertFn('前台弹出的信息');</script>"); 

 

原文地址:https://www.cnblogs.com/zFelix/p/5754080.html