當前位置:編程學習大全網 - 源碼下載 - JS調用CS裏的帶參方法

JS調用CS裏的帶參方法

 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

  • 上一篇:Github 代碼托管如何申請?是免費的麽?
  • 下一篇:為什麽c語言對符號整型溢出沒有規範定義
  • copyright 2024編程學習大全網