問題,如何把上傳檔案的瀏覽按鈕換成其他樣式 或者圖片

來源:互聯網
上載者:User
我的上篇隨筆中,寫了如何替換“瀏覽”按鈕的代碼
有朋友指出 該表單無法提交,
由於我當時只是測試了 能否實現替換和瀏覽
我測試了一下,果然不能提交表單 提示“。。。許可權。。”
後來修改如下

<%@ Page Language="C#" ResponseEncoding="gb2312" debug="true"%>
<%@ import Namespace="System" %>
<%@ import Namespace="System.IO" %>
<!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" xml:lang="gb2312" lang="gb2312">
<head>
<title> 上傳的時候<input type="file">中用圖片代替瀏覽按鈕 </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="title" content="" />
<meta name="author" content="活靶子,huobazi" />
<meta name="subject" content="" />
<meta name="language" content="gb2312" />
<meta name="keywords" content="" />
<meta name="Copyright" content="" />
<meta name="robots" content="all" />
<script language="c#" runat="server">
    void Button_Click(object o , EventArgs e)
    {        
            string str = browse.PostedFile.ContentLength.ToString();
            Response.Write(str);
    }
    void Page_Load(object o , EventArgs e)
    {
        
    }
</script>
<script language="javascript" type="text/javascript">
    function fn_browse()
    {
        document.all.browse.click();
        document.all.file.value = document.all.browse.value;
        
        
    }
    function fn_submit()
    {
        document.forms[0].browse.disabled = true;        
    }
</script>

</head>
<body>

<form runat="server" method="post" enctype="multipart/form-data" >

<input type="file"  id="browse"  runat="server" style="display:none"/>

<input type="text" name="file" />
<a href="#" onclick="fn_browse()">
<img  name="btn" src="browse.gif" border="0" /></a>  
<br />
<br />
<input id="button" type="submit" value="提交" onServerClick="Button_Click" runat="server" 
onclick="fn_submit" />

</form>

</body>
</html>

該表單可以提交了,但是仍然不能上傳所選檔案,不知各位有沒有其他辦法?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.