触发在列表中一一点击-加上全部切换 [英] Trigger click one by one down a list - plus toggle all

查看:79
本文介绍了触发在列表中一一点击-加上全部切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 FIDDLE ,您可以进行分叉工作

Here is the FIDDLE you can fork and work on

给出

<a href="#" class="iconList" id="myDoc_aaa">...</a>
<a href="#" class="iconListChecked" id="myDoc_bbb">...</a>
<a href="#" class="iconList" id="myDoc_ccc">...</a>

我想分配*键来依次触发每个链接上的点击,并分配ctrl- *来触发所有链接上的点击.我不想切换类,因为单击链接时需要运行一个脚本

I want to assign the * key to trigger click on each link in turn and ctrl-* to trigger click on all. I do not want to toggle the class, since there is a script that needs to run when the link is clicked

问题::您能否帮助我使用选择器和其他(数据属性?)来一次在*上一次循环链接,一次在ctrl-star上一次循环链接

QUESTION: Can you help me with the selectors and what else (data attribute?) to loop over the links one at a time on * and all at once on ctrl-star

所以当你

点击*,将触发第一个链接(脚本将类更改为iconListChecked),

hit *, the first link is triggered (and the script changes the class to iconListChecked),

再次点击*星号,并触发第二个链接(取消选中该链接),

hit * star again and the second link is triggered (unchecking it),

点击*,第三个触发,

点击*,然后自动换行,第一个被触发(取消选中)

hit * and we wrap and the first is triggered (unchecking it)

点击ctrl-star并触发所有未检查的链接

hit ctrl-star and all not-checked links are triggered

已修复:$(".iconList").trigger("click");

(我的小提琴目前仅处理数字键盘上的*-我对此

(My fiddle currently only handles the * on the numeric keyboard - I have a separate question for that here)

推荐答案

http://jsfiddle.net/GtXMW/28/

// ... removed unedited part..

// Function to handle *
function toggleFirst() {
    var $candidates = $('.iconList,.iconListChecked');
    var $nottoggled = $candidates.not('.rw_toggled').first();
    if (!$nottoggled.length) {
        // There is no non-toggled element any more.
        // Remove class from all links
        $candidates.removeClass('rw_toggled');
        $nottoggled = $candidates.first();
    }
    // Add temporary class, trigger click
    $nottoggled.addClass('rw_toggled').click();
    console.log("*");
}
// Function to handle ctrl+*
function toggleAll() {
    console.log("ctrl+*");
    $(".iconList").click();
}    
$(document).ready(function() {
    // Handle Ctrl+* and * 
    $(document).keypress(function(e) {
        var $this = $(this);
        if (e.which === 42) { // '*'.charCodeAt(0) === 42
            if (!$this.data('rw_star_pressed')) {
                $this.data('rw_star_pressed', true);
                if (e.ctrlKey) { // Ctrl + *
                    toggleAll();
                } else {             // Just *
                    toggleFirst();
                }
            }
        }
    }).keyup(function() {
        $(this).removeData('rw_star_pressed');
    });

    // ... rest of your original code...
});

这篇关于触发在列表中一一点击-加上全部切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆