html表单怎么上传图片?

html-css017

html表单怎么上传图片?,第1张

html表单这样上传图片:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.mobiletrain.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="www.mobiletrain.org ">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />

<title>上传图片</title>

</head>

一、html在表单元素中这样添加背景图

用户名:<input type="text" name="user" style="background: url(图片路径)" /><br/>

密 码: <input type="password" name="mima" style="background: url(图片路径)" /><br/>

<input type="submit" value="确定" style="background: url(图片路径)" />

<input type="reset" value="取消" style="background: url(图片路径)" />

对于 input 标签,并且 type="file",其在 HTML 中所提供的按钮样式是缺省的,由系统负责解释执行,设置 vaule 是无效的。

解决办法有多种,例如:

将 input 标签设置为隐藏,再添加 1 个 button,点击 button 触发 file 事件。

以下是简单的示例:

 <input type="file" name="picpath" id="picpath" style="display:none">

 <input type="button" value="上传封面" onclick="picpath.click()">