我正在文本输入字段上使用jQuery日期选择器,我不想让用户用键盘更改文本输入框中的任何文本。
下面是我的代码:
$('#rush_needed_by_english').keydown(function() {
//code to not allow any changes to be made to input field
});
如何不允许使用jQuery在文本输入字段中进行键盘键入?
发布于 2010-03-10 08:49:29
$('#rush_needed_by_english').keydown(function() {
//code to not allow any changes to be made to input field
return false;
});
发布于 2010-03-10 08:51:18
您只需使用以下命令将该字段设为只读:
$('#rush_needed_by_english').attr('readonly', 'readonly');
如果您使用的是jQuery 1.6+,则应改用prop()
方法:
$('#rush_needed_by_english').prop('readOnly', true);
// careful, the property name string 'readOnly' is case sensitive!
或者抛弃jQuery,使用普通的JavaScript:
document.getElementById('rush_needed_by_english').readOnly = true;
发布于 2010-03-10 08:48:15
您可以:
$('#rush_needed_by_english').attr('disabled', 'disabled');
https://stackoverflow.com/questions/2413755
复制相似问题