Files
dianming/test.html
2026-04-25 10:09:16 +08:00

75 lines
2.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>二维码测试</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
max-width: 600px;
margin: 0 auto;
}
.test-result {
margin: 20px 0;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
}
#qrcode {
margin: 20px 0;
}
canvas {
border: 2px solid #333;
}
</style>
</head>
<body>
<h1>二维码生成测试</h1>
<div class="test-result">
<h3>测试结果:</h3>
<p id="status">正在检测...</p>
</div>
<div id="qrcode">
<h3>二维码显示区域:</h3>
</div>
<script src="https://cdn.jsdelivr.net/npm/qrcode@1.5.3/build/qrcode.min.js"></script>
<script>
window.addEventListener('load', function() {
const status = document.getElementById('status');
const qrcodeDiv = document.getElementById('qrcode');
if (typeof QRCode !== 'undefined') {
status.innerHTML = '<span style="color: green;">✓ QRCode库加载成功</span>';
// 创建canvas
const canvas = document.createElement('canvas');
qrcodeDiv.appendChild(canvas);
// 生成测试二维码
const testUrl = 'http://example.com?code=123456';
QRCode.toCanvas(canvas, testUrl, {
width: 200,
margin: 2
}, function(error) {
if (error) {
status.innerHTML += '<br><span style="color: red;">✗ 二维码生成失败: ' + error + '</span>';
} else {
status.innerHTML += '<br><span style="color: green;">✓ 二维码生成成功!</span>';
status.innerHTML += '<br>测试URL: ' + testUrl;
}
});
} else {
status.innerHTML = '<span style="color: red;">✗ QRCode库加载失败</span>';
status.innerHTML += '<br>可能原因网络连接问题或CDN被屏蔽';
status.innerHTML += '<br>建议:使用备用方案或手动输入编号';
}
});
</script>
</body>
</html>