简体   繁体   English

Webcam.js 错误:找不到要附加到的 DOM 元素

[英]Webcam.js Error: Could not locate DOM element to attach to

I am trying to use Webcam.js to capture image in my MVC project.我正在尝试使用 Webcam.js 在我的 MVC 项目中捕获图像。 But at the initial level I have an issue "Could not locate DOM element to attach to."但在初始级别,我有一个问题"Could not locate DOM element to attach to."

I have attached script我附上了脚本


<style>
    .Camera {
        width: 320px;
        height: 240px;
        border: 1px solid black;
    }
</style>
<script type="text/javascript" src="~/Scripts/webcam.min.js"></script>
<script language="JavaScript">
    Webcam.set({
        width: 320,
        height: 240,
        image_format: 'jpeg',
        jpeg_quality: 90
    });
     Webcam.attach('#Camera');
</script>

In View在视图中

 <div>
       <div id="Camera" class="Camera"> </div>
    <br>
    <input type="button" id="takeshot" value="Capture" onClick="take_snapshot()" />
 </div>

What is the possible cause?可能的原因是什么?

place your javascript functions beneath the tag/element id:camera and id:takeshot将您的 javascript 函数放在标签/元素 id:camera 和 id:takeshot 下方

Try this: Delete the class Camera, happened with me but after deleting the class and just keeping the "id" it worked.试试这个:删除 class 相机,发生在我身上,但在删除 class 并保持“id”后它工作。

camera = document.getElementById("camera"); camera = document.getElementById("camera");

Webcam.attach(camera);网络摄像头.attach(相机);

Webcam.set({ width:350, height:300, image_format: 'png', png_quality:90 }); Webcam.set({ width:350, height:300, image_format: 'png', png_quality:90 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM