-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e709408
commit ac6df20
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>PWA TEST</title> | ||
<script> | ||
|
||
</script> | ||
</head> | ||
|
||
<body> | ||
<h1>Welcome to the PWA World!</h1> | ||
|
||
<form> | ||
<!-- 图片选择器 --> | ||
<input type="file" id="imageInput" accept="image/*"> | ||
</form> | ||
|
||
<!-- 图片预览容器 --> | ||
<div id="previewContainer"> | ||
<h3>图片预览:</h3> | ||
<img id="preview" src="" alt="Preview" style="max-width: 300px; display: none;"> | ||
</div> | ||
|
||
<script> | ||
// 获取 input 和 img 元素 | ||
const imageInput = document.getElementById('imageInput'); | ||
const preview = document.getElementById('preview'); | ||
|
||
// 当用户选择图片时触发事件 | ||
imageInput.addEventListener('change', function (event) { | ||
const file = event.target.files[0]; // 获取用户选择的文件 | ||
if (file) { | ||
const reader = new FileReader(); // 创建 FileReader 对象 | ||
|
||
// 文件加载完成后,将内容设置为图片的 src | ||
reader.onload = function (e) { | ||
preview.src = e.target.result; | ||
preview.style.display = 'block'; // 显示图片 | ||
}; | ||
|
||
reader.readAsDataURL(file); // 读取文件内容为 DataURL | ||
} else { | ||
preview.style.display = 'none'; // 如果没有文件,隐藏图片预览 | ||
} | ||
}); | ||
</script> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters