【问题标题】:Set value to textbox control将值设置为文本框控件
【发布时间】:2016-01-21 11:50:02
【问题描述】:

如何将年龄值设置为文本框 id is txtage? 我想将年龄设置为文本框值而不是警报框

<asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:TextBox ID="txtDate" runat="server" />
<asp:TextBox ID="txtage" runat="server" />
    <asp:ImageButton runat="server" ID="imgPopup" ImageUrl="~/Images/Calendar.png" />
    <cc1:CalendarExtender ID="CalendarExtender1" OnClientDateSelectionChanged="DateSelectionChanged"
        runat="server" TargetControlID="txtDate" PopupButtonID="imgPopup" />
    <script type="text/javascript">
        function DateSelectionChanged(e) {
            var today = new Date();
            var dob = e.get_selectedDate();
            var months = (today.getMonth() - dob.getMonth() + (12 * (today.getFullYear() - dob.getFullYear())));
            alert("Your age: " + Math.round(months / 12));
        }    
    </script>

【问题讨论】:

标签: javascript jquery asp.net


【解决方案1】:

你必须这样做

$('#<%=txtDate.ClientID %>').val("your value");

asp.net 中使用客户端 ID - 建议使用,但没那么多。我会尽量避免用javascript写ClientID

【讨论】:

  • @UrvishPatel 我可以得到我的学分吗?如果它有助于使其成为答案。并投票
【解决方案2】:

试试这个: 使用 jquery

$('[id$=txtDate]').val('your value');

或使用 javascript

document.getElementById('txtDate').value='your value';

【讨论】:

    猜你喜欢
    • 2013-06-21
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 2012-04-08
    • 2021-11-08
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    相关资源
    最近更新 更多