菜鸟求助,求大神解答一下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title ></title>
</head>
<body>
<script type="text/javascript">
function myfunction() {
alert("Enter ChangeHiddenValue");
var hdnId = "<%=hdnSecretValue.ClientID %>";
var hdn = document.getElementById("hdnId");
var txt = document.getElementById("txtSecretValue");
hdn.value = txt.value;
alert("Value Changed");
}
</script>
<form id="form1" runat="server">
<div>
<h1>HiddenField Control</h1>
<h2>This page was post at <%=DateTime.Now.ToString() %>.</h2>
<asp:HiddenField ID="hdnSecretValue" runat="server"
onvaluechanged="hdnSecretValue_ValueChanged" />
Enter cecret value:
<asp:TextBox ID="txtSecretValue" runat="server"></asp:TextBox>
<br />
<br />
<input type="button" value="change hidden value" onclick="myfunction()" />
<asp:Button ID="btnPost" runat="server" Text="Post" />
<br />
<br />
<asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
为什么无法hdn和txt中没有value??
------解决方案--------------------如果你是想实现将txt的输入值放进hidden里面的话
function myfunction() {
alert("Enter ChangeHiddenValue");
var hdn = document.getElementById("hdnSecretValue");
var txt = document.getElementById("txtSecretValue");
hdn.value = txt.value;
alert("Value Changed");
}