2

I'm trying to implement a Tab key listener for a textbox.

$('#mytextbox').live('keydown', function (e) {
   if (e.keyCode == 9 || e.which == 9) {
      // TO DO SOMETHING
   }
});

However, for some reason I need to limit the tab listener's callback to invoke only when the textbox has changed. Is there anyway to do this?

4

3 に答える 3

1

入力フィールドの値をチェックして、元の値と異なることを確認できますか?

例えば

$('#mytextbox').live('keydown', function (e) {
   if ((e.keyCode == 9 || e.which == 9) && ($('#TextBox').val() != 'Starting Value')) {
      // TO DO SOMETHING
   }
});
于 2013-04-21T08:51:54.597 に答える
0

または、そのテキストボックスの値を保存/認識せずに:

var changed = false;

$('#mytextbox').on('keydown', function (e) {
    if (e.which == 9 && changed) {
        e.preventDefault();
        // TO DO SOMETHING
        alert("works");
        changed = false;
    } else {
        changed = true;
    }
});

http://jsfiddle.net/9a37b/

于 2013-04-21T09:12:36.823 に答える