如何使输入类型编号不可编辑但仍能正常工作? [英] How to make input type number un-editable but still functioning?
问题描述
< input readonly ='readonly'id ='testid'name ='testname'type ='number'min ='1'>
我试过这个,但没有工作。有没有办法做到这一点?如使用CSS或JavaScript。
我的jsfiddle。
http://jsfiddle.net/jmasejo/vta96mp1/
你好我有一个工作代码,但我认为这不是最好的方法。我合并了来自
如何禁用退格,如果输入字段以外的任何事情都集中在使用jquery
和TuomasK的答案这里是我的工作代码。
http://jsfiddle.net/vta96mp1/1/
HTML
< input class ='testInput'id ='testid'value ='1'name =' testname'type ='number'min ='1'>
JS
< pre $ $(#testid)。keypress(function(evt){
evt.preventDefault();
});
$(document).keydown(function(e){
var elid = $(document.activeElement).hasClass('textInput');
console.log(e .keyCode +'&&'+ elid);
if(e.keyCode === 8&&!elid){
return false;
};
});
<input readonly='readonly' id ='testid' name='testname' type='number' min ='1'>
I tried this one but not working. is there any way to do it? like using css or javascript.
my jsfiddle.
http://jsfiddle.net/jmasejo/vta96mp1/
hello I have a working code but i think this is not the best way. I merged the answer from
How to disable backspace if anything other than input field is focused on using jquery
and the answer of TuomasK
here is my working code.
http://jsfiddle.net/vta96mp1/1/
HTML
<input class='testInput' id ='testid' value = '1' name='testname' type='number' min ='1'>
JS
$("#testid").keypress(function (evt) {
evt.preventDefault();
});
$(document).keydown(function(e) {
var elid = $(document.activeElement).hasClass('textInput');
console.log(e.keyCode + ' && ' + elid);
if (e.keyCode === 8 && !elid) {
return false;
};
});
这篇关于如何使输入类型编号不可编辑但仍能正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!