admin管理员组

文章数量:1023187

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

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

本文标签: How do i recognize a ctrlclick on an html webpage with javascriptjqueryStack Overflow