Check if textarea has any characters (and ignore whitespaces) before submitting
I have a simple check .val() == ""
wit开发者_运维技巧h jQuery if textarea is empty or not before submitting. It works, but it counts whitespaces.
How can I ignore white spaces in this check?
// Post guestbook; Check on frontend before submitting
function postGuestbook() {
if ($('.post-form textarea').val() == "")
{
$('div.message.error').show();
return false
}
else {
$('.post-form input[type="submit"]').attr('disabled', 'disabled');
return true;
}
}
...
if ($.trim($('.post-form textarea').val()) == "") {
...
http://api.jquery.com/jQuery.trim/
精彩评论