如何使用JavaScript(VS 2010)清除Calendar控件的选定日期? [英] How to clear the selected date of a Calendar control using JavaScript (VS 2010)?

查看:88
本文介绍了如何使用JavaScript(VS 2010)清除Calendar控件的选定日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用JavaScript清除Calendar控件的选定日期。另外,在执行此操作时,如何防止页面重新加载?



问候!

I would like to know how to clear the selected date of a Calendar control using JavaScript. Also, while doing this, how do I prevent the page from getting reloaded?

Regards!

推荐答案

如果您使用的是JavaScript,则不应重新加载页面。如果它行为奇怪,请尝试附加return false;到您的JavaScript代码,例如OnClick事件。但如果你有正确的设置,它不应该回发页面。



关于日历控件,它取决于你使用的日历控件。但是大多数都允许使用null日期值,或者你可以将它设置为当前日期。



最好的方法是使用jQuery来选择控件但是你可以使用计划JavaScript。如果控件允许空日期,则将其值设置为空字符串值,如。如果没有,您可以将其设置为当前日期或某些通用默认日期,例如01/01/2000。



将其设置为当前日期是最常用的方法,除非您有业务规则来调用其他内容。这是我做过的一个例子。但代码工作将取决于您正在使用的日历控件。您可能会发现需要根据所使用的控件修改jQuery代码。



这是我用来设置日历控件日期的示例函数。您可以调整jQuery以使用当前日期或空字符串来测试您的控件以查看它处理的内容。你可以忽略这里的字符串,因为我用它来维护文化格式。它可能不是你需要的东西,但它可以帮助你,所以我把它留在了。



The page should not reload if you are using JavaScript. If it is acting oddly, try appending "return false;" to your JavaScript code such as the "OnClick" event. But if you have this setup correctly, it should not postback the page.

In regards to the calendar control, it will depend on which calendar control you are using. But most will allow a null date value or you can just set it to the current date.

The best way to do this is to use jQuery to select the control but you can just use plan JavaScript. If the control will allow for a null date, then set it's value to an empty string value like "". If not, you can set it to the current date or some generic default date such as "01/01/2000".

Setting it to the current date is the most common approach unless you have business rules to call for something else. Here's a sample where I have done just that. But the code working will depend on the calendar control you are using. You might find that you need to modify the jQuery code depending on the control you are using.

Here's a sample function I used to set a calendar control's date. You can adjust the jQuery to use the current date or an empty string to test your control to see what it handles. You can ignore the string here, as I was using this to maintain the culture formatting. It's probably not something you need, but it may help you so I left it in.

function setDateControlls(startDate) {
    // Convert to string to preserve the culture specific formatting.
    var sDate = new String(startDate);


get( calFromDate )。value = sDate;
}
get("calFromDate").value = sDate; }





如果以上方式按您希望的方式工作,请尝试将其调整为类似下列。在不知道您正在使用哪个日历控件并能够针对特定日历控件测试代码的情况下,很难猜出您需要什么。





If the above does work the way you want it to, try adjusting it to something like the following. It's hard to guess what you need without knowing which calendar control you are using and being able to test the code against that particular calendar control.

function setDateControlls(startDate) {
    // Convert to string to preserve the culture specific formatting.
    var sDate = new String(startDate);


#calFromDate)值(SDATE);
}
("#calFromDate").value(sDate); }


这篇关于如何使用JavaScript(VS 2010)清除Calendar控件的选定日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆