用html, css, javascript ,怎么让用户要么选择上传自己的图片,要不选择在网页出给出的图片?详情见下

html-css06

用html, css, javascript ,怎么让用户要么选择上传自己的图片,要不选择在网页出给出的图片?详情见下,第1张

可以给文件上传控件再添加一个onclick事件啊,当点击这个input时,把myimg的src赋值给cusInput,然后当onchange事件发生再把上传后的图片地址赋值给cusInput,这样的话即使因为图片路径相同未触发onchange事件,但onclick事件仍然发生了啊,cusInput仍然保留了上一次上传的图片路径:

<input type="file" name="pic" onchange="change(event)" onclick="cusInput=document.getElementById('myimg').src">

直接写

CSS样式

是不行的

<input

type="text"

size="20"

name="upfile"

id="upfile"

style="border:1px

dotted

#ccc">

<input

type="button"

value="浏览"

onclick="path.click()"

style="border:1px

solid

#cccbackground:#fff">

<input

type="file"

id="path"

style="display:none"

onchange="upfile.value=this.value">

写成这样,用一个text和一个button替代file,然后让file隐藏