简体   繁体   English

如何使用ctrl键执行多页超链接点击

[英]How to perform multiple page hyperlink clicks with ctrl key

I would like to know how (if there's a way) to handle multiple link clicks via the ctrl key. 我想知道如何(如果有办法)通过ctrl键处理多个链接点击。

So for example the user would go to a web page with about 3 hyperlinks on it. 因此,例如,用户将转到带有大约3个超链接的网页。 Then the user would hold down the ctrl key, then click one link then another. 然后,用户将按住ctrl键,然后单击一个链接,然后单击另一个链接。 Then when the ctrl key is released, an event will occur (maybe a search based on the combination of both hyperlinks' values). 然后,当释放ctrl键时,将发生一个事件(可能是基于两个超链接值的组合进行搜索)。

I am using C# and assume the solution will probably be done in jQuery? 我正在使用C#,并假定解决方案可能会在jQuery中完成?

The selection should work similar to how windows explorer does. 该选择应类似于Windows Explorer的工作方式。 Where you hold down the ctrl key, then select a file, then another and then cut or paste it somewhere. 在按住ctrl键的位置,选择一个文件,然后选择另一个文件,然后将其剪切或粘贴到某个位置。

I appreciate any help that you could provide as I am struggling to find help elsewhere. 感谢您在我正在其他地方寻求帮助时可以提供的任何帮助。

You could do something like this; 你可以做这样的事情; keep state of the CTRL key (keycode = 17), add links to array when CTRL is pressed down (keydown event), on the keyup event (when keycode == 17) open the links in new windows. 保持CTRL键的状态(键代码= 17),按下CTRL键(键下降事件)时,将链接添加到数组中;在keyup事件中(键代码== 17时),在新窗口中打开链接。 Opening them in tabs is not really possible, however there is a working sample for Firefox; 确实不可能在选项卡中打开它们,但是有一个适用于Firefox的示例。 read this . 阅读

Example: 例:

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">
var ctrlIsDown = false;
var links = new Array();

function afterKeyUp()
{
    if(links.length > 0){
        for(var link in links){
                window.open(links[link]);
        }
        links = new Array();
        $("a").css('color', '');
    }
}

$(document).ready(function(){

$(document).keydown(function(e){ 
    if(e.which == 17) {
        ctrlIsDown = true;
    }
});

$(document).keyup(function(e){ 
    if(e.which == 17) {
        ctrlIsDown = false;
        afterKeyUp();
    }
});

$("a").click(function(e){
    if(ctrlIsDown){
        var href = $(this).attr("href");
        if($.inArray(href, links) == -1)
        {
            links[links.length] = href;
            $(this).css('color', 'red');
        }
    e.preventDefault();
    }
});

});
</script>
</head>
<body>

<a href="1.html">Link 1</a>
<a href="2.html">Link 2</a>
<a href="3.html">Link 3</a>


</body>
</html>

High level idea would be 高层次的想法是

1) Create a css class to highlight selected link 1)创建一个CSS类以突出显示所选链接

2) Write javascript function to detect Ctrl key on KeyDown javsacript event of hyperlinks, this function should toggle the class of hyperlinks to selected link (so that user know which hyperlinks are selected) and add the hyperlink value/url to an hidden field to know the links of selected hyperlinks 2)编写javascript函数以检测超链接的KeyDown javsacript事件上的Ctrl键,此函数应将超链接的类切换到选定的链接(以便用户知道选择了哪些超链接),并将超链接的值/ URL添加到隐藏字段中以了解所选超链接的链接

3) Write javascript function on KeyUp javsacript event on hyperlinks to get the selected links and perform action on it. 3)在超链接的KeyUp javsacript事件上编写javascript函数,以获取选定的链接并对其执行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM