简体   繁体   English

如何在jQuery过滤器中设置日期的默认值

[英]how can i set a default value for date in jQuery filter

I am using a JQuery to show a table out of a database which I am filtering with the datetimepicker . 我正在使用JQuery显示数据库中的表,该数据库正在使用datetimepicker过滤。

What I am trying is to set a default value for my filter as the current day. 我正在尝试将过滤器的默认值设置为当天。
So as default it should only show me data from the current day. 因此,默认情况下,它仅应显示我当天的数据。

I already tried a lot and searched for many questions here, but it didn't really help me. 我已经尝试了很多,并在这里搜索了许多问题,但这并没有真正帮助我。

I tried to set it with JS as defaultDate and tried to set it after initialization with a variable. 我尝试使用JS将其设置为defaultDate,并尝试在初始化后使用变量进行设置。

At the moment it loads all the data out of the database, which takes a bit, so I want to change it to this way. 目前它将所有数据从数据库中加载出来,这需要一点时间,因此我想将其更改为这种方式。

我的过滤器

HTML HTML

<div class='input-group date' id='datepicker1' style="width: 220px;">
    <span class="input-group-addon">
        <span class="glyphicon glyphicon-calendar" aria-hidden="true"></span>
        nach Datum
    </span>
    <input type='text' id="filterdatum" name="datum" value="{FILTERDATUMDEUTSCH}" class="form-control" />
</div>

JS JS

$(document).ready(function() {    

$('#datetimepickerzeit').datetimepicker({
    locale: 'de',
    format: 'DD.MM.YYYY HH:mm:ss'
});
// Datum filtern
$('#datepicker1').datetimepicker({
    locale: 'de',
    format: 'D.M.YYYY'
});
$('#datepicker1').on('dp.show', function () {
    $('#datepicker1').on('dp.change', function () {
        window.location = "?module=ausschuss&action=showtable&filterdate=" + $('#datepicker1').data("DateTimePicker").date().format('YYYY-MM-DD');
    });
});

Two things I'd try. 我会尝试两件事。 First, make sure you have a link to jQuery above your script block. 首先,请确保您在脚本块上方具有指向jQuery的链接。 Use either Google's or a local copy: 使用Google的副本或本地副本:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

If that doesn't work, next try replacing all instances of $ in your Javascript code with jQuery: 如果那不起作用,接下来尝试用jQuery替换Java代码中$的所有实例:

jQuery(function(){ 
 jQuery('#id1').daterangepicker({
    defaultDate: new Date(),
    arrows:true,
    onChange: function(){
       jQuery('#frmDate').submit()
    },
 });
});

you can also try defaultDate: new Date(), in your code. 您还可以在代码中尝试defaultDate:new Date()。

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

相关问题 如何使用jQuery为Flexdatalist设置默认值 - How can I set a default value for Flexdatalist using jQuery 如何在jQuery Datepicker中设置日期范围并将其设置为默认值? - How to set date range in jQuery Datepicker and set it as a default value? 如何在jQuery Datepicker中将“最小日期”设置为默认值 - How to Set Min Date as Default Value in Jquery Datepicker 如何在jquery转发器中为日期类型的输入设置默认值? - How to set default value for input with type of date in jquery repeater? antd 如何设置选择日期为默认日期? - How can I set choosen date as a default date in antd? 如何在 select 中设置默认值? - How can I set a default value in a select? jQuery Datepicker 从日期设置默认值? - jQuery Datepicker set default value from date? 在日期选择器的早期将当前日期设置为默认日期,以便我可以根据当前日期过滤数据 - set the current date as the default early in my datepicker so that I can filter the data according to the current date 如何在jQuery中计算日期,并将输入日期的值设置为? - How can I calculate dates in jQuery, and set an input date's value to that? 如何在jQuery中将开始日期的默认值设置为昨天,将结束日期设置为今天 - How to set default value of start date as yesterday and end date as today in jQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM