[英]How can I Show in JS the button type when the input type “file” is not empty?
這是我表單中的代碼。
我有一個用於加載URL(readURL)的外部JS文件。
我想知道當文件類型為“空”或“不”時如何隱藏和顯示Button。
<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">
使用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">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.