js調用CS裏的方法有很多 我用壹種簡單的方法 如下 CS裏
public string test() { return "Hello World"; }
public string test() { return "Hello World"; } aspx 頁面
< xmlns=" <head runat="server"> <title>無標題頁</title> <mce:script type=text/javascript ><! var demo=function(){ var b= "<%=test() %>"; alert(b); } // ></mce:script> </head> <body> <form id="form " runat="server"> <div> <input type=button id="id " onclick="demo()" value="JS調用CS" /> </div> </form> </body> </>
< xmlns=" <head runat="server"> <title>無標題頁</title> <mce:script type=text/javascript ><! var demo=function(){ var b= "<%=test() %>"; alert(b); } // ></mce:script> </head> <body> <form id="form " runat="server"> <div> <input type=button id="id " onclick="demo()" value="JS調用CS" /> </div> </form> </body> </> 上面的是不帶參數的 要是後臺CS裏方法帶參數就要註意了 CS:
public string test(string a) { return a; } [c sharp] view plaincopy public string test(string a) { return a; } aspx:
< xmlns=" <head runat="server"> <title>無標題頁</title> <mce:script type=text/javascript ><! var demo=function(){ var a="Hello World"; var b= <%=test(" +a+ ") %> ;//這裏壹定註意單引號和雙引號的使用!!!!! alert(b); } // ></mce:script> </head> <body> <form id="form " runat="server"> <div> <input type=button id="id " onclick="demo()" value="JS調用CS" /> </div> </form> </body> </>
lishixinzhi/Article/program/Java/JSP/201311/20133