简体   繁体   中英

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 in 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');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM