javascript - 在ajax成功回调函数中输入type="file"无效的js点击事件
问题描述
如果不知道有没有遇到过这个问题,我一直在困扰这个问题。请问大家,这是为什么呢。
$('.bottom').click(function(){
$('input').click(); // Put on the outside of the ajax can be performed
$.ajax({
type: 'post',
url: url,
data: data,
dataType: 'json',
contentType: 'application/json',
success: function(data){
$('input').click(); // This is invalid
},
error: function(data){
}
});
})
解决方案
@Rachel.C 尝试以下解决方案
$(document).ready(function(){
$('.bottom').click(function(){
$.ajax({
type: 'post',
url: "https://reqres.in/api/users?page=2",
dataType: 'json',
contentType: 'application/json',
crossdomain:true,
async:false,
success: function(data){
alert("2");
$('#iptFile').trigger('click'); // This is invalid
},
error: function(data){
}
});
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button class="bottom">Click me</button>
<input type="file" Id="iptFile"/>
推荐阅读
- html - 父块元素底部的额外空间
- node.js - 在 Angular 7 客户端中获取 Express 应用程序的响应标头
- jquery - JQuery, How to diasable dropdownlists value when other dropdownlist value that selected
- reactjs - 笑话:动作创作者问题
- php - 苏鲁与 Symfony 4
- javascript - 如何使用javascript执行按钮点击操作
- html - 扩展html模板的背景图片没有加载到html页面中,如何解决这个问题?
- java - IntelliJ IDEA 可以自动用变量填充方法调用吗?
- oracle - 在不知道oracle中的列的情况下创建临时表
- vue.js - 没有值的自定义属性名称 - Vue.js