How to make input type number un-editable but still functioning?

前端 未结 3 1809
北荒
北荒 2020-12-22 10:58

I tried this one but not working. is there any way

3条回答
  •  不思量自难忘°
    2020-12-22 11:41

    This is from Disable writing in input type number HTML5, but it requires jQuery.

    $("[type='number']").keypress(function (evt) {
        evt.preventDefault();
    });
    

    Without jQuery code is: (input is an input field)

    input.onkeypress=function(evt){
        evt.preventDefault();
    };
    

提交回复
热议问题