disable text selection except input

前端 未结 3 1876
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 01:01

I\'ve got this snippet of code to disable all text selection. How would I go about disabling all text except for input? I tried $(\'* :not(input)\').disableTextSelec

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-14 01:30

    The problem seems to be that this disabling is inherited. So, even though you aren't selected them in the $() they still get disabled. But this can also be in our favor.

    After disabling, you can enable the inputs.

    $('body').css('MozUserSelect', '-moz-none');
    $('input').css('MozUserSelect', 'text');
    

    NOTE: the value must be '-moz-none'. If 'none', it can't be changed.

    I can't test IE nor do I have a solution for Opera. But maybe this will help part way.

提交回复
热议问题