我想单击按钮2以在按钮1上触发单击事件.我可以使用JQuery完成此任务.
HTML:
Upload File
JS:
$('#upload_input').trigger('click');
我是Ember.js的新手,我想在Ember.View环境中完成相同的功能.预先感谢您的帮助.
解决方法:
只需在输入上使用change事件.然后,您可以发布表单,或使用ajax异步回发.这是一个简单的例子:
视图
App.UploadButtonView = Ember.View.extend({
tagName: 'input',
attributeBindings: ['type'],
type: 'file',
change: function(e){
var self = this;
var formData = new FormData();
formData.append('file', this.$().get(0).files[0]);
$.ajax({
url: '/file_upload/',
type: 'POST',
//Ajax events
success: function(data){ },
error: function(){ },
// Form data
data: formData,
//Options to tell jQuery not to process data or worry about content-type.
cache: false,
contentType: false,
processData: false
});
}
});
模板
{{view 'uploadButton'}}
标签:jquery,javascript,ember-js,html
来源: https://codeday.me/bug/20190703/1363189.html