【问题标题】:How can I Show in JS the button type when the input type "file" is not empty?当输入类型“文件”不为空时,如何在JS中显示按钮类型?
【发布时间】:2019-07-14 08:05:36
【问题描述】:

这是我表单中的代码。

我有一个用于加载 URL (readURL) 的外部 JS 文件。

我想知道当文件类型为空或非空时如何隐藏和显示按钮。

 <input type="file" id="file" name="file" onchange="readURL(this);"/>
    <img src="<c:url value='/test/file'/>" id="newImg">
 <input type="button" id="upload" value="Load">

【问题讨论】:

    标签: javascript java file jsp


    【解决方案1】:

    用 JS 和 Jquery 为您提供快速解决方案:

    var imgVal = $('#file').val(); 
      if(imgVal=='') 
      { 
        $('#upload').hide();
    
      } 
    $('#file').click(function(){
      $('#upload').show();
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <input type="file" id="file">
    <input type="button" id="upload" value="Load">

    【讨论】:

      猜你喜欢
      • 2010-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2021-05-02
      相关资源
      最近更新 更多