gpt4 book ai didi

javascript - 如何从分配的隐藏字段值中获取文本框值

转载 作者:行者123 更新时间:2023-11-28 16:29:05 25 4
gpt4 key购买 nike

我编写了以下脚本,当点击选项卡上的文本框为空时,将隐藏字段的值获取到文本框,但它不起作用,所以任何人都可以告诉它出了什么问题

<script type="text/javascript">
function Tab() {
var PayDate = document.getElementById('txtDate').value;
var hdn1 = document.getElementById('hdn1');
if (PayDate == null) {
// Retreive the next field in the tab sequence, and give it the focus.
document.getElementById('txtDate').value = hdn1.value;
}
}
</script>

<asp:HiddenField ID="hdn1" runat="server" />
<asp:TextBox ID="txtDate" runat="server" onChange="Tab();"></asp:TextBox>
<asp:Button ID="btn" runat="server" Text="Button" />

在我的页面加载上我写了这个

if (!IsPostBack)
{
hdn1.Value = "1-2-2001";
}

但是当我点击选项卡时,我没有获得分配给文本框的隐藏字段的值,任何人都可以帮助我

最佳答案

我认为当您获取文本框和隐藏字段时您需要服务器标记,因为它们是按 ID 在服务器上运行的

<script type="text/javascript">
function Tab() {
var PayDate = document.getElementById('<%= txtDate.ClientID %>').value;
var hdn1 = document.getElementById('<%= hdn1.ClientID %>');
if (PayDate == '') {
// Retreive the next field in the tab sequence, and give it the focus.
document.getElementById('<%= txtDate.ClientID %>').value = hdn1.value;
}
}
</script>

<asp:HiddenField ID="hdn1" runat="server" />
<asp:TextBox ID="txtDate" runat="server" onChange="Tab();"></asp:TextBox>
<asp:Button ID="btn" runat="server" Text="Button" />

关于javascript - 如何从分配的隐藏字段值中获取文本框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6816362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com