issue with using ctrl and click jquery

痴心易碎 提交于 2019-12-11 11:16:22

问题


$('tbl').on('click', 'tbody tr', function(e) {
   if (e.ctrlKey) {
      //fancybox 1 to be appeared
   }
   if(e.shiftKey) {
      //fancybox 2 to be appeared
   }
});

Finding an issue as below:

//comment

having a problem using this, because I even have to render response from the fancybox and display in the td.. when i click it by ctrl+click then I am getting the form load which I seen through debugging tool but sometimes it display the fancybox.

//comment end

I have used the above coding in a table id tbl and tried to select multiple tr using click event and then get a fancybox. So before that I have used the code as

 $('#tbl).on('click','tbody tr',function(e){
      if ($(this).hasClass('fancybox fancybox.ajax')) {
                $(this).removeClass('fancybox fancybox.ajax');
                $(this).css("background", "white");
      }
      else {
           $(this).addClass('fancybox fancybox.ajax');
                    $(this).css("background", "#ffc");
      }
});



   $('tbl').on('click', 'tbody tr', function(e) {
   if (e.ctrlKey) {
      if ($(this).hasClass('fancybox fancybox.ajax')) {
                $(this).removeClass('fancybox fancybox.ajax');
                $(this).css("background", "white");

                //fancybox 1 to be appeared
      }
      else {
           $(this).addClass('fancybox fancybox.ajax');
                    $(this).css("background", "green");
      }
   }
   if(e.shiftKey) {
      if ($(this).hasClass('fancybox fancybox.ajax')) {
                $(this).removeClass('fancybox fancybox.ajax');
                $(this).css("background", "white");
      }
      else {
           $(this).addClass('fancybox fancybox.ajax');
                    $(this).css("background", "yellow");

                    // fancybox 2 to be appeared
      }
   }
});

Later tried to implement above code. Please suggest.

Thanks

来源:https://stackoverflow.com/questions/26464866/issue-with-using-ctrl-and-click-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!