62,074
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#btnSelect').click(function () {
$('#<%=fu.ClientID %>').click();
});
$('#<%=fu.ClientID %>').change(function () {
$('#<%=tb.ClientID %>').val($('#<%=fu.ClientID %>').val());
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:FileUpload ID="fu" runat="server" style="display:none"/>
<asp:TextBox ID="tb" runat="server"></asp:TextBox> <input type="button" value="选择" id="btnSelect" /><br />
<asp:Button ID="btn" runat="server" Text="上传" OnClick="btn1_Click" /><br />
</form>
</body>
</html>
IE 上传要点2次 我也不知道为什么
<div class="divFileUpload">
<div class="one">
<input id="Text1" type="text" class="fileStyle" disabled="disabled" />
<input id="Button2" type="button" value="浏览..." runat="server" class="Button" />
</div>
<div class="two">
<asp:FileUpload ID="file" runat="server" onkeydown="return false;" onchange="document.getElementById('Text1').value = document.getElementById('file').value" />
</div>
</div>
.divFileUpload .one { }
.divFileUpload .two { position: absolute; top: 0px; left: 0px; }
.divFileUpload .two input { font-family: 宋体; font-weight: 400; font-size: 9pt; height: 22px; padding-top: 4px; background: url(images/input_BG.jpg) repeat-x left top; color: #000000; border: 1px solid #76a1aa; width: 265px; opacity: 0; filter: alpha(opacity=0); cursor: pointer; }
原理就是拿div把难看的盖掉……做透明
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="1.php">
<input type="file" id="file"name="file" style="display:none"/>
<input type="button" name="button" value="点我就像点击“浏览”按钮一样" onclick="javascript:openBrowse();" />
<input type="text" id="filename"/>
</form>
</body>
<script type="text/javascript">
function openBrowse(){
var ie=navigator.appName=="Microsoft Internet Explorer" ? true : false;
if(ie){
document.getElementById("file").click();
document.getElementById("filename").value=document.getElementById("file").value;
}else{
var a=document.createEvent("MouseEvents");//FF的处理
a.initEvent("click", true, true);
document.getElementById("file").dispatchEvent(a);
}
}
</script>
</html>