【问题标题】:JQuery how can i check if the textbox is emptyJQuery如何检查文本框是否为空
【发布时间】:2014-04-04 13:37:08
【问题描述】:

当我更改文本框时,我想知道文本框是否为空,我该怎么做?我试图创建一个脚本,但我完全失败了。

我是 jQuery 的新手。

这是我的 js 脚本

$("#description").blur(function())){
if ($("#description").val() == "") alert ("Empty!");
}}

我想知道我的文本区域是否为空

<label>Description</label>
<textarea cols="55" rows="3" id="description" name="description">
</textarea>
<br><br>

我需要做什么?我不想在 textarea 中调用函数

【问题讨论】:

标签: jquery


【解决方案1】:

将其包装在 dom 中

$(document).ready(function () {
    $("#description").blur(function () {
        if ($("#description").val() == "") alert("Empty!");
    });
});

另外你的语法有一些错误

【讨论】:

    【解决方案2】:
    $("#description").blur(function(){
    if ($("#description").val() == ""){ alert ("Empty!")};
    });
    

    【讨论】:

      【解决方案3】:

      使用变化

      $("#description").on('change',function(){
        if(this.value == "") alert("Empty");
      });
      

      【讨论】:

        【解决方案4】:
        $(document).ready(function () {
            if ($('#element').is(':empty')){
               //do something
             }
        });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-10-23
          • 2022-01-09
          相关资源
          最近更新 更多