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>"); 

 

posted @ 2016-08-09 17:34  FelixWeb  阅读(593)  评论(0编辑  收藏  举报