c#中怎样获取js中的变量?
js:vark="da";document.getElementById("Hidden2").value=k;cs:Label1.Text=Hidden2.Value;...
js: var k = "da";document.getElementById("Hidden2").value = k;
cs: Label1.Text = Hidden2.Value;我想问下为什么调试时,发现Hidden2.Value是空值? 展开
cs: Label1.Text = Hidden2.Value;我想问下为什么调试时,发现Hidden2.Value是空值? 展开
2个回答
2013-06-10
展开全部
没问题啊:(注意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;
}
<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;
}
推荐于2018-04-30 · 知道合伙人数码行家
关注
展开全部
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()%>";//硬盘录像机ip
var lPort = "<%=iPort %>";
var lpUserName = "<%=getlpUserName()%>";
var lpPassword = "<%=getlpPassword()%>";
var lChannelNum = "<%=iChannelNum %>";
var UserID
function 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>
前端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()%>";//硬盘录像机ip
var lPort = "<%=iPort %>";
var lpUserName = "<%=getlpUserName()%>";
var lpPassword = "<%=getlpPassword()%>";
var lChannelNum = "<%=iChannelNum %>";
var UserID
function 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>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询