file.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>上传文件</title>
  8. <style>
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. }
  13. .head-btn {
  14. margin: 24px;
  15. text-align: center;
  16. }
  17. .file {
  18. position: relative;
  19. display: inline-block;
  20. border: 1px solid #99D3F5;
  21. border-radius: 10px;
  22. padding: 12px 24px;
  23. overflow: hidden;
  24. background-color: #1975F7;
  25. color: #fff;
  26. text-decoration: none;
  27. text-indent: 0;
  28. line-height: 20px;
  29. font-size: 20px;
  30. }
  31. .file input {
  32. position: absolute;
  33. font-size: 20px;
  34. right: 0;
  35. top: 0;
  36. opacity: 0;
  37. }
  38. /* .file:hover {
  39. background: #AADFFD;
  40. border-color: #78C3F3;
  41. color: #004974;
  42. text-decoration: none;
  43. } */
  44. .determine {
  45. color: #FFFFFF;
  46. background-color: #007AFF;
  47. display: inline-block;
  48. font-size: 20px;
  49. border-radius: 5px;
  50. padding: 8px 24px;
  51. }
  52. .showFileName {
  53. display: inline-block;
  54. height: 30px;
  55. min-width: 300px;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <div class="head-btn">
  61. <form action="" method="post">
  62. <a href="javascript:;" class="file" id="selectFile">选择文件
  63. <input type="file" name="uploadFile" id="uploadFile">
  64. </a>
  65. </form>
  66. <p class="showFileName"></p>
  67. </div>
  68. <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
  69. <script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js">
  70. </script>
  71. <script>
  72. function getQuery(name) { // 获取uni传值
  73. // 正则:[找寻'&' + 'url参数名字' = '值' + '&']('&'可以不存在)
  74. // let reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  75. console.log(window.location.search)
  76. // let r;
  77. // // #ifdef H5
  78. // r = window.location.search.substr(1).match(reg);
  79. // // #endif
  80. // // #ifdef APP-PLUS
  81. // r = window.location.search;
  82. // // #endif
  83. // if(r != null) {
  84. // // 对参数值进行解码
  85. // return unescape(r[2]);
  86. // }
  87. // return null;
  88. }
  89. // console.log(44456,getQuery('token')); // 调用获取参数
  90. $(".file").on("change", "input[type='file']", function() {
  91. let filePath = $(this).val();
  92. // console.log(333, filePath)
  93. // console.log(4444, document.getElementById('uploadFile').files[0])
  94. console.log(5555,document.getElementById('uploadFile'))
  95. var receiver = document.getElementById('uploadFile')
  96. let files = document.getElementById('uploadFile').files[0];
  97. uni.postMessage({
  98. data: {
  99. files: files
  100. }
  101. })
  102. receiver.postMessage("hello there!","*")
  103. localStorage.setItem("fileAddress", filePath);
  104. let lastname = localStorage.getItem("fileAddress");
  105. if (lastname != "") {
  106. $(".showFileName").html(lastname);
  107. } else {
  108. $(".showFileName").html("");
  109. }
  110. });
  111. </script>
  112. </body>
  113. </html>