首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# 與 JavaScript 互相呼叫技巧(三)

     編輯:關於C語言

JS 存取 C# 變數

  1. 隱藏欄位:<input id="hf" type="hidden" runat="server" />,後台賦值 hf.Value = "xxx",JS 讀取 document.getElementById('hf').value
  2. 內嵌輸出:後台 public string N;,前台 var v = '<%=N%>';
  3. 註冊腳本:Page.ClientScript.RegisterStartupScript(this.GetType(), "key", $"var tmp = '{value}';", true);

C# 存取 JS 變數

  1. 隱藏欄位回傳:JS 寫入 document.getElementById('hf').value = jsVar;,後台 Request["hf"]
  2. Cookie/Session:跨頁面傳遞

C# 執行 JS 函式

  1. Page.ClientScript.RegisterStartupScript(type, key, script, true);
  2. Literal 控制項:Literal1.Text = "<script>func()</script>";
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved