我在新工作中维护着别人的代码,在一个大型Websuite类型的项目中,有一个部分是我要使用音频标签而不是嵌入标签重新实现的主体的附加部分。我无法删除它。
过去是这样的:
$('body').append('<embed id="infrSound' + this.id + '" src="' + this.soundfile + '" autostart="true" hidden="true" loop="true" repeat="true" style="display:block; width:0px; height:0px;">');
以下是它过去的删除方式:
$('embed#infrSound' + this.id).remove();
现在是这样工作的:
$('body').append('<audio controls autoplay="autoplay" loop="true" hidden="true" repeat="true"><source id="infrSound' + this.id + '" src="' + this.soundfile + '"></audio>');
在这个新的实现中,我将如何消除声音?
最佳答案
$('source#infrSound' + this.id).parent().remove();
也就是说,使用与以前相同的ID,然后转到其父级,即新的音频标签,然后将其删除。
测试和示例:http://jsfiddle.net/sifriday/pcarjob9/
关于javascript - jQuery如何删除附加的音频标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25212132/