<!DOCTYPE html>
<html>
<head>
    <title>HTML5 QR Code Scanner</title>
    <script src="https://cdn.jsdelivr.net/npm/html5-qrcode"></script>
</head>
<body>
    <h1>Scan QR Code</h1>
    <div id="reader" style="width:600px"></div>
    <p id="result"></p>
    <script type="text/javascript">
        function onScanSuccess(decodedText, decodedResult) {
            // Handle on success condition with the decoded text and result
            console.log(`Code matched = ${decodedText}`, decodedResult);
            document.getElementById("result").innerText = `Scanned code = ${decodedText}`;
        }
        function onScanFailure(error) {
            // Handle on scan failure condition
            console.warn(`Code scan error = ${error}`);
        }
        let html5QrcodeScanner = new Html5QrcodeScanner(
            "reader", { fps: 10, qrbox: 250 });
        html5QrcodeScanner.render(onScanSuccess, onScanFailure);
    </script>
</body>
</html>HTML结构:
<div id="reader">:用于显示扫描二维码的摄像头视图。<p id="result">:用于显示扫描到的二维码内容。JavaScript代码:
html5-qrcode 库,通过 CDN 方式加载。onScanSuccess 和 onScanFailure,分别处理扫描成功和失败的情况。Html5QrcodeScanner 实例,并指定其容器 ID (reader) 和配置参数(如帧率和二维码框大小)。render 方法启动扫描器,传入成功和失败的回调函数。功能:
上一篇:html5教程
下一篇:html 图片
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站