网页升级页面的样式优化

网页升级页面的样式优化lt DOCTYPE html gt lt html gt lt head gt lt meta http equiv Content Type content text html charset utf 8 gt lt title amp

大家好,我是讯享网,很高兴认识大家。

<!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” οnchange=“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=‘file’ name=‘fileField’ class=“file” id=“fileField” size=“28” οnchange= “document.getElementById(‘textfield’).value=this.value” />

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

 <input type=‘button’ class=‘btn’ value=‘浏览…’ />

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

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

小讯
上一篇 2025-01-11 11:41
下一篇 2025-03-12 09:57

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/97808.html