我正在使用jhuckyaby WebcamJS。如果没有检测到网络摄像头显示标识为#forHide
,则显示标识#upload
:
<div class="row" id="forHide">
<div class="d-inline-block ml-3">
<div id="my_camera" class="mb-2"></div>
<input type=button value="Configure" class="btn btn-primary btn-sm ml-1" onClick="configure()">
<input type=button value="Take Snapshot" class="btn btn-primary btn-sm" onClick="take_snapshot()">
<input type=button value="Save Snapshot" class="btn btn-primary btn-sm" onClick="saveSnap()">
</div>
<div class="d-inline-block ml-5">
<div id="results"></div>
</div>
</div>
<div id="upload">
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</div>
我在GitHub上阅读了文档,并尝试实现此代码但不知何故没有结果。
Webcam.on( 'error', function(err) {
// hide element
} );
答案 0 :(得分:0)
检查以下代码,使用纯JavaScript隐藏forHide
ID:
Webcam.on('error', function(err) {
var x = document.getElementById("forHide");
x.style.display = "none";
});
欲了解更多信息,请阅读:https://www.w3schools.com/howto/howto_js_toggle_hide_show.asp