“Ctrl"/“Shift"的 JavaScript 或 jQuery 事件处理程序;+ 鼠标左键单击 [英] JavaScript or jQuery event handlers for "Ctrl"/"Shift" + mouse left button click
本文介绍了“Ctrl"/“Shift"的 JavaScript 或 jQuery 事件处理程序;+ 鼠标左键单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以处理这样的事件:
Is it possible to handle such events as:
- Ctrl + 鼠标左键单击;
- Shift + 鼠标左键单击;
- Alt + 鼠标左键单击通过使用 JavaScript、jQuery 或其他框架.
- Ctrl + mouse left button click;
- Shift + mouse left button click;
- Alt + mouse left button click by using JavaScript, jQuery or other framework.
如果可能,请给出一个代码示例.
If it is possible, please give a code example for it.
推荐答案
你可以这样做(jQuery 用于点击处理程序,但任何框架都适用于重要的部分):
You can do something like this (jQuery for the click handler, but any framework works on the part that matters):
$(selector).click(function(e) {
if(e.shiftKey) {
//Shift-Click
}
if(e.ctrlKey) {
//Ctrl+Click
}
if(e.altKey) {
//Alt+Click
}
});
在点击处理程序中的 if
中处理您想要的任何内容,就像我上面那样.
Just handle whichever you want inside an if
inside the click handler like I have above.
这篇关于“Ctrl"/“Shift"的 JavaScript 或 jQuery 事件处理程序;+ 鼠标左键单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文