编程 自定义input文件上传 file的提示文字及样式

2024-11-17 05:01:13 +0800 CST views 4641
<style>
.upload{
    padding: 4px 10px;
    height: 20px;
    line-height: 20px;
    position: relative;
    text-decoration: none;
    color: #4d90d3;
    cursor: pointer;
}
.replyFileid{
    width:100%;
    position: absolute;
    overflow: hidden;
    right: 0;
    top: 0;
    filter:alpha(opacity=0);
    -moz-opacity:0;
    -khtml-opacity: 0;
    opacity: 0;
    cursor: pointer;
}
.upload span{
    color:#999;
    cursor: pointer;
}
</style>

<a href="javascript:void(0);" class="upload" onclick='javascript:$("#smms_pick").click();'>选择文件  <span id="cxtinfo">未选择任何文件</span>
    <input class="replyFileid" type="file" onchange="smms_cpick1()" id="smms_pick" accept="image/jpeg,image/png,image/gif" style="display:none"/>
</a>
function smms_cpick(){
    if(!document.getElementById('smms_pick').files.length){return;};
    $("#cxtinfo").text(document.getElementById('smms_pick').files[0].name);
    console.log(document.getElementById('smms_pick').files[0].name);
    var myfd=new FormData();myfd.append('file',document.getElementById('smms_pick').files[0]);
        myfd.append("Token","ef03c586c8245c438761a76773d5faf201ebbf19:KsmRlHun4Ea:eyJkZWFkbGluZSI6MTU3NzM3NDAyMCwiYWN0aW9uIjoiZ2V0IiwidWlkIjoiNzAzMTc1IiwiYWlkIjoiMTY0MzQ3NyIsImZyb20iOiJmaWxlIn0=");
    var ajax=$.ajax({url:'http://up.imgapi.com/',type:'POST',processData:false,contentType:false,data:myfd,success:function(res){
        if (res.linkurl){$("#beizhu").val(res.linkurl);}
    }
    });
}

1.png

复制全文 生成海报 前端开发 文件上传 JavaScript HTML AJAX

推荐文章

地图标注管理系统
2024-11-19 09:14:52 +0800 CST
网站日志分析脚本
2024-11-19 03:48:35 +0800 CST
Vue3中如何实现插件?
2024-11-18 04:27:04 +0800 CST
thinkphp分页扩展
2024-11-18 10:18:09 +0800 CST
前端项目中图片的使用规范
2024-11-19 09:30:04 +0800 CST
markdown语法
2024-11-18 18:38:43 +0800 CST
Vue3中怎样处理组件引用?
2024-11-18 23:17:15 +0800 CST
程序员出海搞钱工具库
2024-11-18 22:16:19 +0800 CST
随机分数html
2025-01-25 10:56:34 +0800 CST
如何实现虚拟滚动
2024-11-18 20:50:47 +0800 CST
Linux 网站访问日志分析脚本
2024-11-18 19:58:45 +0800 CST
npm速度过慢的解决办法
2024-11-19 10:10:39 +0800 CST
Elasticsearch 聚合和分析
2024-11-19 06:44:08 +0800 CST
详解 Nginx 的 `sub_filter` 指令
2024-11-19 02:09:49 +0800 CST
内网穿透技术详解与工具对比
2025-04-01 22:12:02 +0800 CST
Vue3中的Slots有哪些变化?
2024-11-18 16:34:49 +0800 CST
Git 常用命令详解
2024-11-18 16:57:24 +0800 CST
程序员茄子在线接单