2015-03-25 13 views
5

versteckt Ich frage mich, ob dies machbar ist? Google kommt mit nichts auf.machen einen Eingabe-Typ "Datei" mit der Schaltfläche

Grundsätzlich möchte ich meine Schaltfläche simulieren, wenn ausgewählt, so dass Benutzer Dateien hochladen können. Ich habe gelesen, seine möglich mit Etiketten, aber ich muss mit einer Taste tun, um zu tun, sieht UX/UI

<button style="position:fixed;bottom:10px;right:70px" type="button" class="btn btn-default" > 
<input type="file" id="files" visbility="hidden"/> 
<span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span> 
</button> 

Zur Zeit meine Taste wie folgt aus: enter image description here dazu:

enter image description here

Antwort

0

So etwas wie dies tun:

<button id="fileup" style="position:fixed;bottom:10px;right:70px" type="button" class="btn btn-default" > 
<input type="file" id="files" visbility="hidden"/> 
<span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span> 
</button> 
<script> 
$('#fileup').click(function() { 
    $('#files').click(); 
}); 
</script> 
+4

Ich glaube, Sie besser die Sichtbarkeit = "hidden", um Stil zu ändern = "display: none" –

20

Sie können tun es tatsächlich mit label, müssen Sie nur die input verstecken.

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/> 
 
<label for="upload"> 
 
     <span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span> 
 
     <input type="file" id="upload" style="display:none"> 
 
    </label>

+0

Beachten Sie, dass es nicht auf alten funktioniert Android 4.2 Browser. –

+0

"für" in der Bezeichnung Tag und "id" in der Eingabe Tag müssen übereinstimmen. Der Rest ist nur zum Stylen. – meles

0

einfache Methode mit schöner Eingabedatei [unterstützen Typ = " Datei"].

Output Bild-URL - https://i.stack.imgur.com/4Jl0H.jpg

input[type="file"] { 
 
\t display: inline-block; 
 
\t opacity: 0; 
 
\t position: absolute; 
 
\t margin-left: 20px; 
 
\t margin-right: 20px; 
 
\t padding-top: 30px; 
 
\t padding-bottom: 67px; 
 
\t width: 85%; 
 
\t z-index: 99; 
 
\t margin-top: 10px; 
 
\t cursor:pointer; 
 
} 
 
.custom-file-upload { 
 
\t position:relative; 
 
    display: inline-block; 
 
    cursor: pointer; 
 
\t padding-top:40px; 
 
\t padding-bottom:40px; 
 
\t background:url(http://www.a-yachtcharter.com/search-fleet/webaccess/assets/img/uploadIcon.png) #fff center center no-repeat; 
 
\t width:91%; 
 
\t border:1px dashed #ff5b57 !important; 
 
\t margin-left:20px; 
 
\t margin-right:20px; 
 
\t margin-top:10px; 
 
\t text-align:center; 
 
}
<input type="file" multiple class="form-control"> 
 
<label for="file-upload" class="custom-file-upload"></label>

Verwandte Themen