disable text selection while pressing 'shift'

前端 未结 5 934
我寻月下人不归
我寻月下人不归 2020-12-08 09:44

I\'m implementing item selection functionality in javascript (using jQuery). item is a li that contains some html.
the user can click on one item (makes it select

5条回答
  •  春和景丽
    2020-12-08 10:26

    Try a combo of JavaScript and css to prevent the selection in the first place:

    $('li').attr('unselectable', 'on'); // IE
    

    css (for browsers not IE):

    li {
                user-select: none; /* CSS3 (little to no support) */
            -ms-user-select: none; /* IE 10+ */
           -moz-user-select: none; /* Gecko (Firefox) */
        -webkit-user-select: none; /* Webkit (Safari, Chrome) */
    }
    

提交回复
热议问题