简体   繁体   English

jQuery datepicker文本框值问题

[英]jquery datepicker textbox value issue

I have 2 text boxes namely fromDate & toDate for date search , in which by default, current day will be showed. 我有2个文本框,分别是fromDate和toDate用于日期搜索,默认情况下将显示当前日期。

working code: 工作代码:

Jquery jQuery的

(document).ready(function () {
    $('.dateClass').datetimepicker({timepicker: false}); // css for displaying date without time

    $('#fromDateId').datetimepicker({value: '01-01-2016', format: 'd-M-Y'});     // display current date with dd-mmm-yyyy        
    $('#toDateId').datetimepicker({value: '01-01-2016', format: 'd-M-Y'});       // display current date with dd-mmm-yyyy  
});   

Struts 支柱

<html:text property="fromDate"  styleId="fromDateId" styleClass="dateClass"  />
<html:text property="toDate"  styleId="toDateId" styleClass="dateClass"  />

Issue: 问题:

By default current day shown in both textboxes, suppose user choose different dates and submit, db records are fetched and displayed but these 2 texboxes replaced with current dates how to avoid this. 默认情况下,两个文本框中都显示了当前日期,假设用户选择了不同的日期并提交,则获取并显示了数据库记录,但是将这2个texbox替换为当前日期可以避免这种情况。

kindly help me to resolve. 请帮助我解决。

Update: There are reports this no longer works in Chrome. 更新:有报告称此功能不再适用于Chrome。

This is concise and does the job: 这很简洁,可以完成工作:

$(".fromDateId").datepicker('setDate', new Date());

And another thing, 还有一件事,

$(function()
{
    $('.date-pick').datePicker().val(new Date().asString()).trigger('change');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM