gpt4 book ai didi

html - 如何将div作为输入

转载 作者:太空宇宙 更新时间:2023-11-04 00:44:13 25 4
gpt4 key购买 nike

在我的 Angular 应用程序中,我有一个自定义图像网格,当我在最后一张图像之后自定义了带有一些 fa-icon 和文本的 div,当用户单击它时想要在 pc 中显示图像选择窗口

我试过把<input #imgeSelecter type="file" accept=".png, .jpg, .jpeg" (change)="openImageSelector(imgeSelecter)"/>在我的 cutome 中制作了 div 并将其命名为 input{display:none}在 css 中,但没有任何反应。我将在这篇文章中附上图片

 <div class="upload-img-placeholder">
<fa-icon class="textfeild-icon [icon]="['fas', 'upload']">
</fa-icon>
<input
#imgeSelecter
type="file"
accept=".png, .jpg, .jpeg"
(change)="openImageSelector(imgeSelecter)"
/>
<span>
Upload photos
</span>

<span class="upload-img-messege">
You can upload # more photos
</span>
</div>


.upload-img-placeholder {
input {
//display: none;

}
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: percentageCalculator(16);
background-color: #e3e7eb;
height: percentageCalculator(130);
width: percentageCalculator(165);
border-radius: percentageCalculator(6);
margin-left: percentageCalculator(20);
margin-top: percentageCalculator(27);
color: $sub-title-dark-color;
cursor: pointer;
//opacity: 0.4;
> .upload-img-messege {
font-size: percentageCalculator(14);
opacity: 0.7;
margin-left: percentageCalculator(25);
margin-right: percentageCalculator(20);
cursor: pointer;
}
}

enter image description here

最佳答案

最简单的方法

组件.html

  <input type="file" id="file" (change)="uploadFile($event.target.files[0])" accept="image/*">

<div class="container" (click)="openFileUpload()">
<p>Upload Photos <p>
</div>

<p>{{file?.name}} </p>

组件.css

#file{
display: none;
}

.container{
width: 150px;
height: 150px;
background-color: grey;
text-align: center;
cursor: poiner;
}

组件.ts

  openFileUpload() {
document.getElementById('file').click();
}

uploadFile(file) {
console.log(file);
}

stackblitz 示例 https://stackblitz.com/edit/angular-zdnjja?file=src%2Fapp%2Fapp.component.ts

关于html - 如何将div作为输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57621823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com