c# – 从服务器端调用Javascript函数
发布时间:2020-12-15 19:38:03 所属栏目:百科 来源:网络整理
导读:在按钮上单击我调用服务器端功能,我在其中调用 Javascript函数 Page.ClientScript.RegisterStartupScript( this.GetType(),"scriptsKey","script type="text/JavaScript" language="javascript"test();/script"); 但是Javascript函数没有调用. 解决方法
在按钮上单击我调用服务器端功能,我在其中调用
Javascript函数
Page.ClientScript.RegisterStartupScript( this.GetType(),"scriptsKey","<script type="text/JavaScript" language="javascript">test();</script>"); 但是Javascript函数没有调用. 解决方法
你可以从后面的代码调用函数,如下所示:
MyForm.aspx.cs protected void MyButton_Click(object sender,EventArgs e) { Page.ClientScript.RegisterStartupScript(this.GetType(),"myScript","AnotherFunction();",true); } MyForm.aspx <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>My Page</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> function Test() { alert("hi"); $("#ButtonRow").show(); } function AnotherFunction() { alert("This is another function"); } </script> </head> <body> <form id="form2" runat="server"> <table> <tr><td> <asp:RadioButtonList ID="SearchCategory" runat="server" onchange="Test()" RepeatDirection="Horizontal" BorderStyle="Solid"> <asp:ListItem>Merchant</asp:ListItem> <asp:ListItem>Store</asp:ListItem> <asp:ListItem>Terminal</asp:ListItem> </asp:RadioButtonList> </td> </tr> <tr id="ButtonRow"style="display:none"> <td> <asp:Button ID="MyButton" runat="server" Text="Click Here" OnClick="MyButton_Click" /> </td> </tr> </table> </form> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |