Я использую следующий код для создания окна загрузки файла. но текст справки внутри div с id 'uploadHelp' не отображается. Если я удалю позицию «абсолютный» из css, она начнет отображаться, но тогда поле загрузки файла не будет доступно, поскольку оно было покрыто div uploadHelp.Текст не отображается за файлом ввода
<html>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
<style>
.cf-container{
overflow-y:auto;
overflow-x:hidden;
height:192px;
}
#file-input-container {
width: 94%;
height: 80px;
border: 2px dashed rgb(202, 206, 223);
background: transparent;
border-radius: 4px;
color: #444;
font-weight: 400;
font-size: 16px;
margin: 15px;
overflow-x: hidden;
}
#file-input {
background: transparent;
border: none;
height: 100%;
width: 100%;
opacity: 0;
margin: 0;
cursor: pointer;
}
.cf-upload-help {
position: absolute;
z-index: -1;
text-align: center;
padding-top: 15px;
width: 90%;
margin: 0 auto;
}
</style>
<div>
<!-- Modal -->
<div class="modal fade" id="uploadModal" role="dialog" aria-labelledby="uploadModalLabel" aria-hidden="true"
style="margin-top: 25px;" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body" style="padding: 0px">
<div style="text-align:center">
<div id="file-input-container">
<div class="cf-upload-help" id="uploadHelp">
<div>Click to choose a file</div>
<div>or</div>
<div style="font-size:12px">Drop the file here</div>
</div>
<input type="file" id="file-input" />
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div style="width: 100%; text-align: center;padding-top: 50px;">
<button id="showUpload">Upload</button>
</table>
</div>
</div>
</div>
<script>
$("#file-input").change(function() {
var input = document.getElementById("file-input");
if (input.value) {
$("#uploadHelp").html("Uploading...");
}
});
$("#showUpload").click(function() {
$("#uploadModal").modal("show");
});
</script>
</html>
Это облегченная версия кода, в полный код, я вижу текст в uploadHelp DIV, даже с позиции «абсолюта». Вот дополнительный код в полной версии -
$("#file-input").change(function() {
var input = $("#file-input");
if (input.value) {
$("#uploadHelp").html("Uploaded");
}
});
Но как только я выбираю файл, модальное окно становится пустым и ничего не отображается.
JSFiddle - https://jsfiddle.net/w949yg76/
Вы можете положить, что в jsfiddle для нас? – vdwijngaert
сделано. https://jsfiddle.net/w949yg76/ – cssnoob