日期:2014-05-16  浏览次数:20380 次

JS调用CS里的带参方法 .

js调用CS里的方法有很多,我用一种简单的方法,如下

CS里

[c-sharp] view plaincopyprint?
  1. public string test()  
  2.  {  
  3.     return "Hello World";  
  4.  }  

aspx 页面

[c-sharp] view plaincopyprint?
  1. <html xmlns="http://www.w3.org/1999/xhtml">  
  2. <head runat="server">  
  3.     <title>无标题页</title>  
  4.     <mce:script type="text/javascript" ><!--  
  5.      var demo=function(){  
  6.        var b= "<%=test() %>";  
  7.        alert(b);  
  8.        }  
  9.       
  10. // --></mce:script>   
  11. </head>  
  12. <body>  
  13.     <form id="form1" runat="server">  
  14.     <div>  
  15.         <input type="button" id="id1" onclick="demo()" value="JS调用CS" />  
  16.     </div>  
  17.     </form>  
  18. </body>  
  19. </html>