c#中怎样获取js中的变量?

js: var k = "da";document.getElementById("Hidden2").value = k;
cs: Label1.Text = Hidden2.Value;我想问下为什么调试时,发现Hidden2.Value是空值?

肥皂起泡泡
浏览 1131回答 2
2回答

喵喵时光机

js调用后台方法和变量前端javascript脚本<script language="javascript" type="text/javascript">// var lpServerIP = "192.168.2.180";//硬盘录像机ip// var lPort = 8001;// var lpUserName = "admin";// var lpPassword = "12345";// var lChannelNum = 2;var lpServerIP = "<%=getIpServerIP()%>";//硬盘录像机ipvar lPort = "<%=iPort %>";var lpUserName = "<%=getlpUserName()%>";var lpPassword = "<%=getlpPassword()%>";var lChannelNum = "<%=iChannelNum %>";var UserIDfunction Play(){var i;var Netocx = document.getElementById("NetOCX");UserID = Netocx.Login(lpServerIP,lPort,lpUserName,lpPassword);i = Netocx.StartRealPlay(lChannelNum,0, 0);if (i == 0){alert("预览失败!");}}function Stop(){var Netocx = document.getElementById("NetOCX");Netocx.StopRealPlay();Netocx.Logout();}function FullScreen(){var Netocx = document.getElementById("NetOCX");Netocx.FullScreenCtrl();}function Play1(){var Netocx1 = document.getElementById("NetOCX1");UserID = Netocx1.Login("172.7.76.85",8000,"admin","12345");Netocx1.StartRealPlay(0 ,0, 0);}function Stop1(){var Netocx1 = document.getElementById("NetOCX1");Netocx1.StopRealPlay();Netocx1.Logout();}</script>

BIG阳

没问题啊:(注意script的位置)<body><form id="form1" runat="server"><div><asp:HiddenField ID="HiddenField1" runat="server" /><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /></div></form><script type="text/javascript">var k = "Pa";document.getElementById("HiddenField1").value = k;</script></body>单击Button1时 Label1显示为Pa后台代码:protected void Button1_Click(object sender, EventArgs e){this.Label1.Text = HiddenField1.Value;}
打开App,查看更多内容
随时随地看视频慕课网APP