Selecting multiple from an html select element without using ctrl key

前端 未结 7 2126
灰色年华
灰色年华 2020-11-27 05:44

I\'ve come across various solutions to this issue on the net.

Basically, I find having to hold down ctrl a bit cheesy, and I want the select list to just select what

相关标签:
7条回答
  • 2020-11-27 06:26

    Tony's answer makes the select arrows buggy, as they work only if you hold the mouse down.

    I've combined a few solutions into this, and it works fine at least in Chrome and FF:

    // multiple select: selectable without Control
    $('select[multiple] option').on('mousedown', function(e) {
        var $this = $(this),
            that = this,
            scroll = that.parentElement.scrollTop;
    
        e.preventDefault();
        $this.prop('selected', !$this.prop('selected'));
    
        setTimeout(function() {
            that.parentElement.scrollTop = scroll;
        }, 0);
    
        return false;
    });
    
    0 讨论(0)
提交回复
热议问题