所有控制台日志和警报都在发生,但按钮仍然没有被实际点击。
init: function() {
$('input[type=file]').change(function() {
$(this).closest('.btn-upload').toggleClass('active');
$('#button-submit').click(function() {
console.log("event listening")
});
$('#button-submit').click();
});
}
<div>
<input type="file" id="button-upload">
<input type="submit" id="button-submit">
</div>
答案 0 :(得分:0)
您已将事件处理程序附加到并单击文件输入而不是按钮,因为您在选择器末尾缺少-button
。
应该是:
init: function() {
$('input[type=file]').change(function() {
$(this).closest('.btn-upload').toggleClass('active');
$('#edit-submitted-student-membership-student-id-upload-upload-button').click(function(e) {
e.stopPropagation();
console.log("event listening")
});
$('#edit-submitted-student-membership-student-id-upload-upload-button').click();
alert('asdfdf');
});
}
<div>
<input type="file" id="edit-submitted-student-membership-student-id-upload-upload">
<input type="submit" id="edit-submitted-student-membership-student-id-upload-upload-button">
</div>