Here is sample code:
http://jsfiddle.net/BSjGX/1/
<input id="testing" />
$('#testing')
.keydown(function(e){
if(e.keyCode==13) {return false;}
})
.change(function(){
$('body').append('<br />changed');
});
How do you ppl do开发者_如何学Cing it in IE7 / IE8 etc?
Thanks ;)
Problem is, that the fact that it's changed has already occurred before your code is used.
So you can eat the change, but then on blur, it won't react that it's changed. Try this:
$('#testing')
.change(function(e){
if (e.keyCode == 13) {
e.preventDefault();
return false;
}
$('body').append('<br />changed');
});
I think you'll see what I mean. I think to do what you want, you might need to have your own variable, and track changes.
The change()
event is firing when the <input>
s value is changed. The value is updated when the <input>
loses focus. You could add a blur()
handler to intercept the "change".
精彩评论