Jquery回调在bootstrap选项卡中没有触发
Jquery call back not firing in bootstrap tab
除非我将代码粘贴到控制台中,否则我似乎无法让我的回调触发。如果我这样做,它就会起作用。似乎是某种范围问题或其他东西,因为引导选项卡的动态性质。
HTML<input type="file" class="fileElem pull-right" id="logoUpload" multiple onchange="handleFiles(this.files)">
<ul id="files"></ul>
<span class="fileSelect pull-right" id="logoSelectUpload"> Choose File</span>
金桥
//turn the bootstrap tab on so elements are ready
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
function click(el) {
// Simulate click on the element.
var evt = document.createEvent('Event');
evt.initEvent('click', true, true);
el.dispatchEvent(evt);
}
document.querySelector('#logoSelectUpload').addEventListener('click', function(e) {
var fileInput = document.querySelector('#logoUpload');
//click(fileInput); // Simulate the click with a custom event.
fileInput.click(); // Or, use the native click() of the file input.
}, false);
//callback will only work if I paste it into the console
function handleFiles(files) {
//call backs
var list = [].slice.call(files).map(function(file) {
return '<li>' + file.name + '</li>';
}).join('');
document.getElementById('files').innerHTML = list;
}
});
回调函数的作用域在事件处理程序中。试一试:
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
function click(el) {
// Simulate click on the element.
var evt = document.createEvent('Event');
evt.initEvent('click', true, true);
el.dispatchEvent(evt);
}
document.querySelector('#logoSelectUpload').addEventListener('click', function(e) {
var fileInput = document.querySelector('#logoUpload');
//click(fileInput); // Simulate the click with a custom event.
fileInput.click(); // Or, use the native click() of the file input.
}, false);
//callback will only work if I paste it into the console
});
function handleFiles(files) {
//call backs
var list = [].slice.call(files).map(function(file) {
return '<li>' + file.name + '</li>';
}).join('');
document.getElementById('files').innerHTML = list;
}
相关文章:
- AngularJS:我可以跳过函数参数回调吗
- 要求未定义JS回调参数
- MeteorJS:在带有回调的vzaar api上正确使用wrapAsync
- 自引用回调
- 测试Angular Service解决错误回调中的promise
- 如何将一个JavaScript函数回调为多个函数
- JavaScript回调函数
- 用于回调的javascript参数
- 将json回调数据转换为日期
- 承诺在非节点式回调上使用Bluebird
- 如何在回调函数中执行流
- 回调函数中传递参数的困难(Google Map API Markers)
- 在ajax回调(safari)中调用bootstrap模式显示
- Twitter Bootstrap Popover添加了一个带有事件的回调函数
- $.post 和 $.ajax 回调未与 Bootstrap 一起运行
- 为什么我可以't打开BootStrap模式,同时执行jQuery回调函数
- 带有回调的Bootstrap通用模态
- Jquery回调在bootstrap选项卡中没有触发
- Bootstrap typeahead没有为具有更新程序回调的字段设置值
- 当我们在bootstrap中使用data-target时回调