使用shift和鼠标单击选择多个元素 - jquery [英] selecting multiple elements using shift and mouse click - jquery
问题描述
是否可以使用shift和鼠标单击使用jquery在页面上选择多个元素?
Is it possible to use shift and mouse click to select multiple elements on a page using jquery?
我有几个div,我已经给出了tabindex,以便我可以选择它们并可以执行删除它们等操作。
I have several divs that i have given a tabindex to so that i can select them and can do things like delete them etc.
我希望能够通过按住shift并使用鼠标单击每个来选择多于1个div和我正在努力做到这一点。
I want to be able to select more than 1 by holding down shift and using the mouse to click on each div and am struggling to do this.
有谁知道如何做到这一点?
Does anyone know how this can be done?
推荐答案
我之前用jQuery做了类似的事情:
I did something like that some time ago, with jQuery:
$(id).click(function(event){ //Mouse Click+shift event
if(event.shiftKey){
//give some attribute that can indentify the elements of the selection
//example rel='multi-selection' or class='multi-selection'
}
});
然后你应该做选择这个元素的函数并做你需要的任何事情,我用它来拖动多个元素。例如,如果你想删除这个div,你可以举例如:
Then you should do functions that select this elements and do whatever you need, I used this to drag multiple elements. Example if you want to delete this divs, you can for example:
function deleteMultiSelection(){
$('html').find('div[rel=multi-selection']).each(function(){
$(this).remove();
})
}
$("#button").click(function(){
deleteMultiSelection();
})
请注意,因为我没有测试此代码。
Be careful because I didn't test this code.
这篇关于使用shift和鼠标单击选择多个元素 - jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!