init
This commit is contained in:
38
app.js
Normal file
38
app.js
Normal file
@@ -0,0 +1,38 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const imageInput = document.getElementById('imageInput');
|
||||
const previewImage = document.getElementById('previewImage');
|
||||
const recognizeBtn = document.getElementById('recognizeBtn');
|
||||
const resultText = document.getElementById('resultText');
|
||||
|
||||
// 图片选择事件
|
||||
imageInput.addEventListener('change', function() {
|
||||
const file = this.files[0];
|
||||
if (file) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
previewImage.src = e.target.result;
|
||||
}
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
});
|
||||
|
||||
// 识别按钮点击事件
|
||||
recognizeBtn.addEventListener('click', function() {
|
||||
if (!imageInput.files[0]) {
|
||||
alert('请先选择一张图片');
|
||||
return;
|
||||
}
|
||||
|
||||
// 这里可以添加实际的识别逻辑
|
||||
// 目前使用模拟识别结果
|
||||
const fakeResults = [
|
||||
'这是一只猫',
|
||||
'这是一只狗',
|
||||
'这是一朵花',
|
||||
'这是一辆车'
|
||||
];
|
||||
const randomResult = fakeResults[Math.floor(Math.random() * fakeResults.length)];
|
||||
|
||||
resultText.textContent = randomResult;
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user