<input type="file" />,美化自定义上传按钮

妖狐艹你老母 2022-01-05 14:41 410阅读 0赞

上传的按钮实在是太丑了,今天看了别人的文章,自己找了找资料,琢磨了一下,结果如下。

图片如下:

  1. ![05171134-2246e6d94558456cbb8f463ab8beca4b.png][]

代码如下,粘贴即可以用:

  1. @{
  2. ViewBag.Title = "IndexInput";
  3. Layout = "";
  4. }
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9. <title>input file 美化</title>
  10. <style>
  11. *
  12. {
  13. margin: 0;
  14. padding: 0;
  15. }
  16. .btn_addPic
  17. {
  18. display: block;
  19. position: relative;
  20. width: 120px;
  21. height: 28px;
  22. overflow: hidden;
  23. border: 1px solid #EBEBEB;
  24. background: none repeat scroll 0 0 #F3F3F3;
  25. color: #999999;
  26. cursor: pointer;
  27. text-align: center;
  28. float: left;
  29. margin-right:5px;
  30. }
  31. .btn_addPic span
  32. {
  33. cursor: pointer;
  34. display: block;
  35. line-height: 28px;
  36. }
  37. .filePrew
  38. {
  39. cursor: pointer;
  40. position: absolute;
  41. top: 0;
  42. left:0;
  43. width: 120px;
  44. height: 30px;
  45. font-size: 100px; /* 增大不同浏览器的可点击区域 */
  46. opacity: 0; /* 实现的关键点 */
  47. filter: alpha(opacity=0); /* 兼容IE */
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <form action="@Url.Action("IndexInput", "Uploader")" method="post" enctype="multipart/form-data" >
  53. <div style="height: 28px;margin:100px;">
  54. <div class="btn_addPic">
  55. <span>上传图片…</span><input tabindex="3" title="支持jpg、jpeg、gif、png格式,文件小于5M" size="3"
  56. name="pic" class="filePrew" type="file" οnchange="document.getElementById('textName').value=this.value">
  57. </div>
  58. <input type="text" id="textName" style="height: 28px;border:1px solid #f1f1f1" />
  59. </div>
  60. <br />
  61. <br />
  62. <input type="submit" />
  63. </form>
  64. </body>
  65. </html>

cs 代码 如下:

  1. [HttpPost]
  2. public ActionResult IndexInput(int? page)
  3. {
  4. HttpPostedFileBase saaa = Request.Files["upfile"];
  5. HttpPostedFileBase baseFile = Request.Files[0];
  6. string qqfile = Path.GetFileName(baseFile.FileName);
  7. Stream stream = baseFile.InputStream;
  8. using (var flieStream = new FileStream(HttpContext.Server.MapPath(@"\ImageNew\") + qqfile, FileMode.Create))
  9. {
  10. stream.CopyTo(flieStream);
  11. }
  12. return Content("上传成功!");
  13. }

转载于:https://www.cnblogs.com/Kummy/archive/2013/06/03/3115103.html

发表评论

表情:
评论列表 (有 0 条评论,410人围观)

还没有评论,来说两句吧...

相关阅读