网页升级页面的样式优化

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>定义input type="file" 的样式</title>
<style type="text/css">
body{ font-size:14px;}
input{ vertical-align:middle; margin:0; padding:0}
.file-box{ position:relative;width:340px}
.pathfile{ height:22px; border:1px solid #cdcdcd; width:180px;}
.btn{ background-color:#FFF; border:1px solid #CDCDCD;height:24px; width:70px;}
.file{ position:absolute; top:0; right:80px;filter:alpha(opacity:0);opacity: 0;height:24px;width:70px }
</style>
</head>
<body>
<div class="file-box">
  <form action="" method="post" enctype="multipart/form-data">
 <input type='text' name='textfield' id='textfield' class='pathfile' />  
 <input type='button' class='btn' value='浏览...' />
<input type="file" name="fileField" class="file" id="fileField" size="28" onchange="document.getElementById('textfield').value=this.value" />
 <input type="submit" name="submit" class="btn" value="上传" />
  </form>
</div>
</body>

</html>



样式图片:

原理解说:

原始的标签样式太难看,不太符合要求;

ie 和Google的样式有少些区别,主要是按钮的位置有所不同导致的;

实现方法:

将升级的一样内容放到一个div 下面,并style="position:relative;"

<input type='text' name='textfield' id='textfield' class='txt' /> 

这个文本框设置为只读的模式,用来显示要升级的文件的路径和名称;

<input type='file' name='fileField' class="file" id="fileField" size="28" onchange= "document.getElementById('textfield').value=this.value" />

这个文本框type=file ,点击是将获取的要升级的文件路径和名称同步到上面的制度文本框中

 <input type='button' class='btn' value='浏览...' />

这个按钮,在页面显示浏览按钮的,他没有触发的处理行为,只是用来显示用的,

将type=file 的文本框设置宽度和大小和显示浏览的按钮长度和宽度一样大小,然后通过filter滤镜进行透明化处理

<input type="submit" name="submit" class="btn" value="上传" />

将数据提交给服务器







猜你喜欢

转载自blog.csdn.net/wangzhen_csdn/article/details/80619670