duandu8202 2015-01-27 06:17 采纳率: 0%
浏览 246
已采纳

使用jQuery判断文件输入字段是否为空

I have a PHP form with a file input field, and two text input fields. What I want to do is use jQuery to check if the file input field is empty, and if it's not, then show a specific div, but the following code does not work:

<input type="file" name="blog-entry-image" id="blog-entry-image" />

var fileInput = $.trim($("#blog-entry-image").val());
if (fileInput.length > 0) {
        $("#new-blogentry").click(function() {
        $("#sending").show();
        return true;
    }); 
}

"new-blogentry" is the submit button, and "sending" is a div with an animated gif.

  • 写回答

5条回答 默认 最新

  • douxianwu2221 2015-01-27 06:23
    关注
    <input type="file" name="blog-entry-image" id="blog-entry-image" />
    
    $(document).ready(function (){
        $("#blog-entry").click(function() {
            var fileInput = $.trim($("#blog-entry-image").val());
            if (fileInput && fileInput !== '') {      
                    $("#sending").show();
                    return true;    
            }
      });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器