我试图遍历9 * 9数独网格的单元格。当在文本框中输入1到9的数字时,我只想提醒。
$('table tr td input').on({"change": function () {
var cell = $(this).val();
alert("Cell Value = " + cell);
}});
以上代码仅在用户将光标移出文本框时发出警报。但是我希望它一进入就行。怎么做?
答案 0 :(得分:2)
答案 1 :(得分:1)
您可以将input
方法用作事件:
$('table tr td input').on({"input": function () {
根据您的评论,您必须使用keyup
事件,因为input
事件未向您提供密码访问权限:
$('input').on({
"keyup": function (e) {
var cell = $(this).val(),
kc = e.which || e.keyCode; // get the keycode
if (kc !== 8 && kc !== 46) { // alert only if not backspace and delete
alert("Cell Value = " + cell);
}
}
});
答案 2 :(得分:0)
您必须使用key up事件来获取值
$('table tr td input').on({"keyup": function () {
var cell = $(this).val();
alert("Cell Value = " + cell);
}});