javascript - 单击时 JQuery on('click') 不起作用
问题描述
所以我目前正在做这个项目,我遇到了这个问题。我尝试查看控制台,但单击按钮时它没有显示任何内容。我想要做的是当我点击按钮时,它会触发文件输入,但到目前为止,当我点击它时,什么也没发生,甚至没有显示错误。(代码基于this中的答案问题:引导表单上传文件布局)你们能帮我找出我做错了什么吗
这些是代码
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 版。
提前致谢
解决方案
您的选择器包含需要像这样转义的正斜杠:
$("#btn_IdentitasKTP\\/Paspor'")
推荐阅读
- python - 如何减少“readline()”从串行数据中花费的时间
- neo4j - What does parameters limit and maxLevel mean in Neo4j apoc query?
- python - Gensim 的 Doc2Vec - 如何使用预训练的 word2vec(单词相似性)
- javascript - 以不同的方法再次使用 componentDidMount 中的 fetch 方法
- javascript - 如何获取对象范围外的回调事件?
- php - 无法在 Prestashop 上的 Smarty 中将两个变量相乘
- c# - Bootstrap 警报可关闭在 Blazor 客户端(WebAssembly)上不起作用
- typescript - 区分 TypeScript 对象类型和类类型的方法
- python - 仅更新值的动态字典创建
- spring-webflow - 在流中访问多个请求参数