How do i recognize a ctrl+click on an html webpage with javascriptjquery? - Stack Overflow

I am making an application which makes use of context menus and has selection.Right now i can select

I am making an application which makes use of context menus and has selection. Right now i can select 1 element, but what i want to do is to ctrl+click to allow me to say append the elements into an array for the selection of MULTIPLE elements simultaneously. That way i can affect the attributes of N things at the same time.

I Need it to be something like Control+Clicking, if there was a better idea, i could be interested. Maybe Shift+click but that has the general understanding of selecting everything ebtween X and Y, where as users are more familiar with clicking individual items with ctrl.

I know how to do the append thing, but i wasnt sure how to do the:

var ev = mouse||window.event;
var t_sel = ev.target || ev.srcElement;
 ...

I am making an application which makes use of context menus and has selection. Right now i can select 1 element, but what i want to do is to ctrl+click to allow me to say append the elements into an array for the selection of MULTIPLE elements simultaneously. That way i can affect the attributes of N things at the same time.

I Need it to be something like Control+Clicking, if there was a better idea, i could be interested. Maybe Shift+click but that has the general understanding of selecting everything ebtween X and Y, where as users are more familiar with clicking individual items with ctrl.

I know how to do the append thing, but i wasnt sure how to do the:

var ev = mouse||window.event;
var t_sel = ev.target || ev.srcElement;
 ...
Share Improve this question asked Jun 28, 2012 at 13:28 FallenreaperFallenreaper 10.7k15 gold badges75 silver badges140 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4
$('.item').click(function(e) {
    if (e.ctrlKey || e.metaKey) {
        // required code to make selection
        // propably, add class to item to style it like selected item and check hidden checkbox
        $(this).toogleClass('selected');
        $(this).find('input[type=checkbox]').attr('checked', !$(this).find('input[type=checkbox]')('checked'));
    }
});

This will allow you to detect a control click:

$(document).click(function(e) {
  if(e.ctrlKey) {
    //You do your stuff here.
  }
});

I've used shiftcheckbox to have the ability to select a range of checkboxes in a grid. The code is available so you can alter it to fit your needs. You may also use it as inspiration for a functionallity that suits you. https://github./nylen/shiftcheckbox

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745590953a4634827.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信