【发布时间】:2019-02-19 00:04:48
【问题描述】:
所以我目前正在从事这个项目,但我遇到了这个问题。我尝试查看控制台,但单击按钮时它没有显示任何内容。我想要做的是当我点击按钮时,它会触发文件输入,但到目前为止,当我点击它时,什么也没发生,甚至没有显示错误。(代码基于this中的答案问题:Bootstrap form upload file layout) 你们能帮我找出我做错了什么
这些是代码
TabUploadDokumen.html
<script>
$(document).ready(function () {
/* Some code here */
});
$('#btn_IdentitasKTP/Paspor').on('click', function () {
$('#file_IdentitasKTP/Paspor').trigger('click')
});
$('#file_IdentitasKTP/Paspor').change(function () {
var file_name = this.value.replace(/\\/g, '/').replace(/.*\//, '');
$('#text_IdentitasKTP/Paspor').val(file_name);
});
</script>
<!--Some other code -->
<div class='form-group'>
<label class='control-label'>Nama Dokumen<br /><span style='font-weight:normal;'>Silahkan scan/foto dokumen Anda disini</span></label>
<div class='form-group'>
<label for="text_IdentitasKTP/Paspor" id="lbl_IdentitasKTP/Paspor" class="control-label">Identitas(KTP/Paspor)</label>
</div>
<div class="input-group">
<input type="file" id="file_IdentitasKTP/Paspor" name="name_file_IdentitasKTP/Paspor" accept="image/jpg,image/jpeg,application/pdf,image/png" style="display: none" />
<input type="text" class="form-control" id="text_IdentitasKTP/Paspor" readonly />
<span class="input-group-btn">
<button class="btn btn-default" type="button" id="btn_IdentitasKTP/Paspor">Upload KTP/Paspor</button>
</span>
</div>`
</div>
<!-- Some other code -->
如果有帮助的话,我正在使用 ASP.NET MVC 5 和 Bootstrap 3.00 版和 Jquery 版 jquery 1.11.1 版。
提前致谢
【问题讨论】:
-
为什么你的 jQuery 代码在 ready 函数之外?
-
@Alexander De Sousa 感谢您指出这一点,我像 vhr 所说的那样添加了双反斜杠,并将其移到了 ready 函数中,现在它可以工作了
标签: javascript jquery html