开发者

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/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜