开发者

Live checking value of textarea

I have a textarea that have a id upload-message. And this jvavscript:

 // step-2 happens in the browser dialog
            $('#upload-message').change(function() {
                $('.step-3').removeClass('error');
                $('.details').removeClass('error');
            });

But how can i check this live? Now, i type 开发者_如何学JAVAin the upload message textarea. And go out of the textarea. Than the jquery function is fired. But how can i do this live?

Thanks


With .keyup:

$('#upload-message').keyup(function() {
    $('.step-3, .details').removeClass('error');
});

However, this'll keep on running for every keypress, which in the case you provided does not make sense.

You should rather bind it once with one:

$('#upload-message').one('keyup', function() {
    $('.step-3, .details').removeClass('error');
});

...so that this event will only fire once.


Simply bind some code to the keyup event:

$('#upload-message').keyup(function(){
    //this code fires every time the user releases a key
    $('.step-3').removeClass('error');
    $('.details').removeClass('error');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜