如何在动态范围的元素上添加一个类

How to add a class on a dynamic range of elements - jQuery

本文关键字:一个 添加 动态 范围 元素      更新时间:2023-09-26

我正试图使Date Range Picker类似于这个

我试过用

这样的东西
     $('#calendar-dates').on('mouseover', 'td', function() {
         if($(this).html() > window.start){
          $(this).addClass("added");
        }
     });
      $('#calendar-dates').on('click', 'td', function() {
        window.start = $(this).html(); // get the number of the day
        $(this).addClass("start"); // to mark it the date-selection start
      });

我想要的是,如果我在this day之后的td元素上用鼠标点击horizontally,用background-color来突出显示它们

如果我去vertically改变前一行的background-color

我读过slice,但我想不明白如何正确利用它。

同样使用mouseover,在一个点之后停止突出显示元素。

请帮。

你可以试试这个

$( "#calendar-dates" ).mouseover(function() {
       // do something 
}).click(function() {
      // do something 
});