我正在尝试使用 wavesurfer.js 为使用 JavaScript 动态创建的元素创建波形。这是我的代码:
$(document).ready(function() {
var id = 9;
$("#audio").append('<div class="row" id="wave' + id + '"></div>');
$('#audio').on('DOMNodeInserted', 'div', function() {
var selectedId = $(this).prop('id');
console.log(selectedId);
window['waveForm' + selectedId] = Object.create(WaveSurfer);
window['waveForm' + selectedId].init({
container: $(this),
waveColor: 'violet',
progressColor: 'purple'
});
window['waveForm' + selectedId].on('ready', function() {
window['waveForm' + selectedId].play();
});
window['waveForm' + selectedId].load(selectedId + '.mp3');
});
});
console.log 显示元素的正确 id,因此选择器似乎可以工作,但是 wavesurfer.js 给出以下错误:
Uncaught TypeError: this.container.appendChild is not a function