input[type=file]文件样式太丑,自定义样式

原始的file控件在搜狗浏览器上很丑。自定义样式使其美观。

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>定义input type="file" 的样式</title>
<style type="text/css">
.file-box{ position:relative;width:340px}
.txt{ 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; height:24px; filter:alpha(opacity:0);opacity: 0;width:260px }
</style>
<script>
	function tt(){
		var fileField=document.getElementById('fileField').value;
		var files=fileField.split("\\");
		document.getElementById('textfield').value=files[files.length-1];
	}
</script>
</head>
<body>
<div class="file-box">
  <form action="" method="post" enctype="multipart/form-data">
	 <input type='text' name='textfield' id='textfield' class='txt' />  
	 <input type='button' class='btn' value='浏览...' />
	 <input type="file" name="fileField" class="file" id="fileField" size="28" onchange="tt()" />
  </form>
</div>
</body>
</html>

相关推荐