最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disable direct value editing in input type="number" - Stack Overflow

programmeradmin2浏览0评论

i have using<input type="number">. in that i don't want user can enter manually numbers in to input. user only increase and decrees numbers by step then is it possible.

i have using<input type="number">. in that i don't want user can enter manually numbers in to input. user only increase and decrees numbers by step then is it possible.

Share Improve this question asked Jun 24, 2014 at 7:43 Devang KateliyaDevang Kateliya 831 gold badge1 silver badge3 bronze badges 2
  • Try this: Spinner - jQuery UI – pes502 Commented Jun 24, 2014 at 7:45
  • 1 I don't think it's possible to disable one particular function of an element like that, but it certainly would be possible to replicate by creating two buttons of your own and making the input read only. – scragar Commented Jun 24, 2014 at 7:46
Add a ment  | 

3 Answers 3

Reset to default 13

You can do it by cancelling the keydown event. Either inline (<input type="number" onkeydown="return false">), or within an event handler.

Use jQuery

$('input[type="number"]').keydown(function (e) {
  e.preventDefault();
});

Use readonly attribute to input.

<input type="number" readonly>

Demo

发布评论

评论列表(0)

  1. 暂无评论