Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何显示开始日期在一个月内,结束日期在另一个月内的元素?_Javascript_Jquery_Html_Date - Fatal编程技术网

Javascript 如何显示开始日期在一个月内,结束日期在另一个月内的元素?

Javascript 如何显示开始日期在一个月内,结束日期在另一个月内的元素?,javascript,jquery,html,date,Javascript,Jquery,Html,Date,我试图只显示与特定月份相关的元素。我正在使用PHP制作一个选择框,该框的值是月份的第一天和最后一天 以下是选择框的结果HTML: <select id="month" name="monthdaterange"> <option value="1427864400,1430370000">April</option> <option value="1430456400,1433048400">May</option>

我试图只显示与特定月份相关的元素。我正在使用PHP制作一个选择框,该框的值是月份的第一天和最后一天

以下是选择框的结果HTML:

<select id="month" name="monthdaterange">
    <option value="1427864400,1430370000">April</option>
    <option value="1430456400,1433048400">May</option>
    <option value="1433134800,1435640400">June</option>
    <option value="1435726800,1438318800">July</option>
    <option value="1438405200,1440997200">August</option>
    <option value="1441083600,1443589200">September</option>
    <option value="1443675600,1446267600">October</option>
    <option value="1446354000,1448863200">November</option>
    <option value="1448949600,1451541600">December</option>
    <option value="1451628000,1454220000">January</option>
    <option value="1454306400,1456725600">February</option>
    <option value="1456812000,1459400400">March</option>
</select>
我遇到的问题是上述因素。它的开始日期是4月,结束日期是5月。这意味着选中时,它应在两个月内显示。但它只在4月份出现。我缺少什么使其在选择任何月份时显示日期范围在两个或多个月之间的元素


这里有一个代码笔:

如果你只关心它是否在那个月,那么就使用这个月的开始日期

换行

if(jQuery(this).attr('data-start-date') >= firstofmonth || jQuery(this).attr('data-end-date') >= lastofmonth){


不管月底是什么时候,你只需要知道该事件是否在本月1号之后继续进行

逻辑是错误的,试试这个

$('.special-container').each( function( index, value ){
    $(this).addClass('hidden');
    if(
      ($(this).attr('data-start-date') >= firstofmonth && $(this).attr('data-start-date') <= lastofmonth) ||
      ($(this).attr('data-end-date') <= lastofmonth && $(this).attr('data-end-date') >= firstofmonth)) {
        $(this).removeClass('hidden');
    }
});
$('.special container')。每个(函数(索引、值){
$(this.addClass('hidden');
如果(

($(this.attr('data-start-date')>=firstofmonth&&$(this.attr('data-start-date')=$(this.attr('data-start-date')&&firstofmonth=$(this.attr('data-start-date')&&lastofmonth=firstofmonth&&$(this.attr('data-start-date'))谢谢,这似乎是在耍把戏,在看了之后,我已经为这个逻辑设置好了它,但我似乎混淆了我需要最后一个月。在进一步测试后,这还没有100%起作用。如果我只有在7月才有一个特辑,它将在选择4月、5月、6月和7月时显示?我只想在7月显示这个特辑y、 有什么想法吗?我试过使用这个,但是如果特价的日期是2015年4月1日到2016年4月1日,那么特价只会在4月份显示,而不是在任何选择上。你能提供这个特价日期的示例吗?$('.special container')。每个(函数(index,value){$(this.addClass('hidden');if((firstofmonth>=$(this).attr('data-start-date')&&firstofmonth=$(this).attr('data-start-date')&&lastofmonth这是我从注释和其他示例中添加代码的代码笔。我仍然看不到我正在寻找的行为。这些时间戳和文本有问题,请先仔细检查
if(jQuery(this).attr('data-start-date') >= firstofmonth || jQuery(this).attr('data-end-date') >= lastofmonth){
if(jQuery(this).attr('data-start-date') >= firstofmonth || jQuery(this).attr('data-end-date') >= firstofmonth ){
$('.special-container').each( function( index, value ){
    $(this).addClass('hidden');
    if(
      ($(this).attr('data-start-date') >= firstofmonth && $(this).attr('data-start-date') <= lastofmonth) ||
      ($(this).attr('data-end-date') <= lastofmonth && $(this).attr('data-end-date') >= firstofmonth)) {
        $(this).removeClass('hidden');
    }
});
$('.special-container').each( function( index, value ){
  $(this).addClass('hidden');
  if( 
     (firstofmonth >= $(this).attr('data-start-date') && firstofmonth <= $(this).attr('data-end-date')) || 
     (lastofmonth >= $(this).attr('data-start-date') && lastofmonth <= $(this).attr('data-end-date')) ||
     ($(this).attr('data-start-date') >= firstofmonth && $(this).attr('data-start-date') <= lastofmonth)
  ) {
    $(this).removeClass('hidden');
  }
});