最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin3PV0评论

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

Post a comment

comment list (0)

  1. No comments so far