简体   繁体   English

如何在动态范围的元素上添加类-jQuery

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

I'm trying to make Date Range Picker similar to this . 我正在尝试使Date Range Picker类似。

I've tried using things like 我已经尝试使用类似的东西

     $('#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

      });

What I want is if I go horizontally with the mouse button over the td elements that come after this day , to highlight them with a background-color 我想要的是,如果我在this day之后出现的td元素上使用鼠标按钮horizontally ,以使用background-color突出显示它们

OR 要么

if I go vertically to change the background-color of the previous row. 如果我vertically去改变上一行的background-color

I have read about slice but I can't think to understand how to utilize it properly. 我已经读过关于slice但是我想不起来如何正确地利用它。

Also using mouseover , after a point it stops highlighting elements. 同样使用mouseover ,在一点之后它也停止突出显示元素。

Please help. 请帮忙。

you can try this. 你可以试试看

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

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

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