菜鸟求助,求大神解答一下

黄瓜味儿 2014-04-23 11:52:19
<!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??
...全文
107 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
黄瓜味儿 2014-04-23
  • 打赏
  • 举报
回复
是不是加了ASP:的元素就不能在script中调用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");
    }

87,902

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧