C#调用js && js调用C#事件

 

js:

       <script type="text/javascript">

        function ss() {

            alert("底层调用js,调用成功!");

        }

        //这个方法用了调用隐藏按钮

        function xx() {

            document.getElementById("Button2").click();

        }

      </script>


 

html:

   <asp:Button ID="Button1" runat="server" Text="底层调用js" onclick="Button1_Click" />


        <hr />


        <input type="button" value="js调用底层" onclick="xx();" />


        <asp:Button ID="Button2" runat="server" Text="我是隐藏按钮" onclick="Button2_Click" style="display:none;"/>


        <hr />


CS:

   

 //底层调用js


    protected void Button1_Click(object sender, EventArgs e)


    {


        Page.ClientScript.RegisterStartupScript(ClientScript.GetType(), "gg", "<script>ss(); </script>");


    }


    


    //后台方法


    public void showval()


    {


        Response.Write("js调用后台方法成功!");


    }




    //隐藏按钮事件


    protected void Button2_Click(object sender, EventArgs e)


    {


        showval();


    }


没有更多推荐了,返回首页