如何在 JavaScript 中清除带有日历扩展器的文本框?

发布于 2024-07-26 16:20:39 字数 170 浏览 4 评论 0原文

我在 ASP.NET 3.5 项目中有一个与日历扩展器和屏蔽编辑扩展器关联的文本框。 我想在 OnBlur 时清除文本框...我尝试使用下面的代码,但它不起作用! 有什么想法吗?

document.getElementById('txtDtTo').value ="";

i have a textbox associated with a calendar extender and a masked edit extender in a asp.net 3.5 project. i would like to clear the texbox when OnBlur...i have tried using the code below but it not working! any ideas guy?

document.getElementById('txtDtTo').value ="";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寻梦旅人 2024-08-02 16:20:39
$('#<%= txtDtTo.ClientID %>').val('');
$('#<%= txtDtTo.ClientID %>').val('');
此刻的回忆 2024-08-02 16:20:39

有许多关于 OnBlur 事件触发的报告问题,清除文本框的代码看起来不错。 为什么当它失去焦点时你需要它为空? 您可以使用 OnChange 事件,但是如果我正确理解您提出的逻辑,您将始终有一个空文本框!

There are many reported problems with the OnBlur event firing, the code to clear the text box looks fine. Why do you need it empty when it loses focus? You could use the OnChange event instead however if I understand your proposed logic correctly you'll always have an empty text box!

白芷 2024-08-02 16:20:39

用这个:

document.getElementById("<%=txtDtTo.ClientID%>").value ="";

use this:

document.getElementById("<%=txtDtTo.ClientID%>").value ="";
合约呢 2024-08-02 16:20:39

这对我有用 http:// /www.aspsnippets.com/Articles/Clear-Selected-Date-of-ASPNet-AJAX-CalendarExtender-using-JavaScript.aspx

<ajax:CalendarExtender Format="dd/MM/yyyy"
                       ID="txtBillDate_CalendarExtender" 
                       BehaviorID = "txtBillDate_CalendarExtender"
                       OnClientDateSelectionChanged="checkDate"
                       TargetControlID="txtBillDate" 
                       runat="server">
</ajax:CalendarExtender>

function checkDate(sender, args) {
    if (sender._selectedDate > new Date()) {
        showAutoCloseMessage('You cannot select a future date! ', 'warning');
        $find("txtBillDate_CalendarExtender").set_selectedDate(null);
        $("[id*=txtBillDate_CalendarExtender]").val("");
        $(".ajax__calendar_active").removeClass("ajax__calendar_active");
        return false;
    }
}

This worked for me http://www.aspsnippets.com/Articles/Clear-Selected-Date-of-ASPNet-AJAX-CalendarExtender-using-JavaScript.aspx

<ajax:CalendarExtender Format="dd/MM/yyyy"
                       ID="txtBillDate_CalendarExtender" 
                       BehaviorID = "txtBillDate_CalendarExtender"
                       OnClientDateSelectionChanged="checkDate"
                       TargetControlID="txtBillDate" 
                       runat="server">
</ajax:CalendarExtender>

function checkDate(sender, args) {
    if (sender._selectedDate > new Date()) {
        showAutoCloseMessage('You cannot select a future date! ', 'warning');
        $find("txtBillDate_CalendarExtender").set_selectedDate(null);
        $("[id*=txtBillDate_CalendarExtender]").val("");
        $(".ajax__calendar_active").removeClass("ajax__calendar_active");
        return false;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文