我有一个包含三个只读列的网格。每当用户进入那里并尝试通过按退格键进行编辑时,我需要通过发送消息来提醒。我正在使用这个脚本,但它不起作用?谁能纠正我?
$(document).ready(function () {
$('#txtCode').bind('keypress', function (e) {
if (e.which == 8) {
alert('The column is read-only and is not editable');
}
}
});
最佳答案
尝试使用 keyup
或 keydown
和 .on()
方法代替 keypress
:
$('#txtCode').on('keyup keydown', function (e) {
您也可以像这样绑定(bind)多个事件。
$('#txtCode')
的另一件事似乎丢失了 });
$(document).ready(function () {
$('#txtCode').on('keyup keydown', function (e) {
if (e.which == 8) {
alert('The column is read-only and is not editable');
}
}); //<----");" this is the closing you misssed this
});
关于javascript - 在文本框中按下退格键时发出警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20780213/