单击默认照片时,用户应该从计算机中选择一个文件,而不是制作一个文件input type = "file"
这使得用户首先单击浏览按钮而不是选择文件。用户应直接单击默认照片,然后会出现一个文件选择窗口。
<html lang = "en">
<head>
<title>
Profile Click
</title>
<style>
#file{
display: none;
}
</style>
</head>
<body>
<script>
function pro1(){
document.prolis.getElementById("image") = document.prolis.getElementById("file");
}
</script>
<form name = "prolis">
<img src = "index.jpg" id = "image" onclick = "pro1()";>
<input type = "file" id = "file">
</body>
</html>
Mozilla Firefox console shows "TypeError: document.prolis.getElementById is not a function".
我应该如何让这个功能发挥作用?
这是我的默认图像:
为了使image
表现得像一个输入file
元素,你可以直接调用input
file .click()
方法,当你点击img
.
您的代码应该是这样的:
function pro1(){
document.getElementById("file").click();
}
Demo:
<html lang = "en">
<head>
<title>
Profile Click
</title>
<style>
#file{
display: none;
}
</style>
</head>
<body>
<script>
function pro1(){
document.getElementById("file").click();
}
</script>
<form name = "prolis">
<img src = "index.jpg" id = "image" onclick = "pro1()";>
<input type = "file" id = "file">
</body>
</html>
Note:
你只需要使用document.getElementById("file")
通过其访问元素id
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)