gpt4 book ai didi

javascript - 用图像替换 CHOOSE FILE

转载 作者:行者123 更新时间:2023-11-27 23:18:04 24 4
gpt4 key购买 nike

您好,我正在尝试用图像替换选择文件按钮。我正在使用 javascript 创建按钮,但是当我检查网站时,它向我显示了一个类型为文件的按钮的 html 脚本。

为了创建它,我使用了:

input = createFileInput(handleFile);
input.elt.style["width"] = "40%";
input.elt.style["font-size"]="3vmin";

function handleFile(file) {
print(file);
if (file.type === 'image') {
imgFile = file.data;
img = createImg(file.data);
img.hide();
canvas.image(img, 0, 0, 224, 224);
image(img, 0, 0, width, height/2);
img.remove();
}
mode = 1;
tint = false;
}

谁能建议我如何用图像更改通用按钮。

最佳答案

我认为您可以作弊并将图像放置在输入上,然后向图像添加点击处理程序并将其传递到下面的输入按钮。

这就是您要实现的目标吗?

const input = document.querySelector("#avatar");
const button = document.querySelector("#button");

button.addEventListener('click', event => input.click(event));
.body {
font-family: sans-serif;
}

label {
display: inline-block;
padding: 1em 0;
}

.wrapper {
position: relative;
}

#avatar {
display: block;
height: 50px;
border: 1px solid #333;
}

#button {
position: absolute;
left: 1px;
top: 1px;
}
<div class="body">
<label for="avatar">Choose a profile picture:</label>
<div class="wrapper">
<input type="file" id="avatar" name="avatar">
<img id="button" src="https://via.placeholder.com/75x50/333333/ffffff?text=Avatar"></img>
</div>
</div>

关于javascript - 用图像替换 CHOOSE FILE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58158851/

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