How to detect Ctrl+V, Ctrl+C using JavaScript?

前端 未结 17 2056
走了就别回头了
走了就别回头了 2020-11-22 13:47

How to detect ctrl+v, ctrl+c using Javascript?

I need to restrict pasting in my textareas, end user should not copy and p

17条回答
  •  萌比男神i
    2020-11-22 14:47

    i already have your problem and i solved it by the following code .. that accept only numbers

    $('#<%= mobileTextBox.ClientID %>').keydown(function(e) {
                ///// e.which Values
                // 8  : BackSpace , 46 : Delete , 37 : Left , 39 : Rigth , 144: Num Lock 
                if (e.which != 8 && e.which != 46 && e.which != 37 && e.which != 39 && e.which != 144
                    && (e.which < 96 || e.which > 105 )) {
                    return false;
                }
            });
    

    you can detect Ctrl id e.which == 17

提交回复
热议问题