简体   繁体   English

keyUp是否有其他选择可以检查输入是否已填充?

[英]Is there any alternative to keyUp to check whether an input was filled?

So I have this code: 所以我有这段代码:

    $(document).ready(function(){
        if($('#proofAttach-filemanager').val().length !=0){
            $('#download_now').attr('disabled', false);
        }
        else
        {
            $('#download_now').attr('disabled', true);        
        }
    });  

The field with id proofAttach-filemanager is filled up dynamically using elFinder every time I upload a file. 每次我上传文件时,使用elFinder动态填充ID 证明为proofAttach-filemanager的字段。

Since the code above is only running every time the page loads, I don't know how to update the download_now button to enable dynamically every time the field is filled (and without keyUp) 由于上面的代码仅在页面每次加载时运行,因此我不知道如何更新download_now按钮以在每次填充字段时动态启用(并且没有keyUp)

HTML Segment: HTML段:

<div class="form-group col-md-12">

<label>Attachment</label>
<input type="text" id="proofAttach-filemanager" name="proofAttach" value="" class="form-control" readonly="">

<div class="btn-group" role="group" aria-label="..." style="margin-top: 3px;">
  <button type="button" data-inputid="proofAttach-filemanager" class="btn btn-default popup_selector">
    <i class="fa fa-cloud-upload"></i> Browse uploads</button>
  <button type="button" data-inputid="proofAttach-filemanager" id="download_now" class="btn btn-default download_now">
    <i class="fa fa-cloud-download"></i> Download</button>
    <button type="button" data-inputid="proofAttach-filemanager" class="btn btn-default clear_elfinder_picker">
    <i class="fa fa-eraser"></i> Clear</button>
</div>

Writing your logic inside the change event of that text box should work. 在该文本框的change事件内编写逻辑应该可以。

$(document).ready(function(){
   toggleDownloadButtonAccess();

   $('#proofAttach-filemanager').change(toggleDownloadButtonAccess);

  function toggleDownloadButtonAccess(){

    var $btnDownload = $('#download_now');    
    if($('#proofAttach-filemanager').val().length !=0){
       $btnDownload.attr('disabled', false);
    }
    else
    {
       $btnDownload.attr('disabled', true);        
    }
   }


 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM