Jquery UI Spinner - Disable Keyboard Input

青春壹個敷衍的年華 提交于 2019-12-05 06:25:46

Simple! Replace

$(".spinner").unbind("keypress");

with

$(".spinner").bind("keydown", function (event) {
    event.preventDefault();
});

Unbind will just unbind the functions that have been binded. A textfields default behavior wont be changed; so we have to prevent that! If you don't want it to focus at all:

$(".spinner").focus(function () {
    $(this).blur();
});

Happy coding!

You can simply add readonly attribute to your label like this:

<input type="text" class="spinner" value="10" readonly/>

this works for me! Cheers

One may want to avoid unbinding and prefer using the existing API's onchange callback:

jquery UI Spinner change event

Discard the change if out of your boundaries.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!