检查文本框为空,然后运行code [英] check if text box is empty then run code

查看:134
本文介绍了检查文本框为空,然后运行code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下jQuery和要检查code运行前的文本框为空的:

I have the following jquery and want to check if the text box is empty before the code is run:

<script type="text/javascript">
    $(document).ready(function () {
        if ($("#FNameTB").val().length < 0) {
            $("input#FNameTB").labelify({ labelledClass: "greylabel" });
        }       
</script>

但它不工作。

推荐答案

长度绝不会小于0

if ( $("#FNameTB").val().length === 0 ) 

您甚至可以添加在TRIM(),以彻底

You can even add in a trim() to be thorough

if ( $("#FNameTB").val().trim().length === 0 ) 

这篇关于检查文本框为空,然后运行code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆