从div中删除jQuery对象 [英] Removing jQuery object from div
问题描述
我可能有错误的措辞,但我所做的是使用以下jQuery库来实现使用HTML5和webRTC的QR阅读器。
I may have the wrong wording for this, but what I have done is used the following jQuery library to implement a QR reader using HTML5 and webRTC.
我有这个在模态中,当模态关闭时,我希望能够停止使用网络摄像头以及停止尝试解释QR码。
I have this in a modal, and when the modal closes I would like to be able to stop using the webcam as well as stop trying to interpret QR codes.
所以我尝试过此代码段中列出的一些内容:
So I've tried a few things outlined in this code snippet:
$("#qrReader_modal").on('hidden', function(){
// Pausing the actual video element
$("#html5_qrcode_video").pause();
// Removing all elements in the div the qr reader was attached to
$("#reader").empty();
});
然而,两者都不起作用。
However, neither works.
在第一种情况下,它继续使用我的相机,图书馆继续尝试读取QR码。
In the first case, it continues to use my camera, and the library continues to try and read a QR code.
在第二种情况下,div被正确清空,但是库然后开始抛出读取错误,网络摄像头仍在尝试捕获视频。
In the second case, the div is correctly emptied, but the library then starts to throw read errors, and the webcam is still trying to capture video.
我会使用unbind函数,但我没有使用bind来附加html5_qrcode_reader。见这里:
I would use the unbind function, but I didn't use bind to attach the html5_qrcode_reader. See here:
$("#reader").html5_qrcode(function(data){...});
所以我的问题是从$(#reader中删除html5_qrcode的正确方法是什么)div
So my question is what is the proper way to remove the html5_qrcode from the $("#reader") div
推荐答案
你必须调用 html5_qrcode_stop()
函数,其中关闭计时器。
请参阅实施 https:// github .com / dwa012 / html5-qrcode / blob / master / src / html5-qrcode.js#L70
You have to call html5_qrcode_stop()
function, which turns off the timer.
See implementation https://github.com/dwa012/html5-qrcode/blob/master/src/html5-qrcode.js#L70
这篇关于从div中删除jQuery对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!