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

2024-11-17 05:01:13 +0800 CST views 4136
<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

推荐文章

Vue3结合Driver.js实现新手指引功能
2024-11-19 08:46:50 +0800 CST
使用Python实现邮件自动化
2024-11-18 20:18:14 +0800 CST
windows安装sphinx3.0.3(中文检索)
2024-11-17 05:23:31 +0800 CST
Nginx 性能优化有这篇就够了!
2024-11-19 01:57:41 +0800 CST
Vue3中如何处理组件间的动画?
2024-11-17 04:54:49 +0800 CST
html一份退出酒场的告知书
2024-11-18 18:14:45 +0800 CST
Vue3中如何进行性能优化?
2024-11-17 22:52:59 +0800 CST
55个常用的JavaScript代码段
2024-11-18 22:38:45 +0800 CST
mysql删除重复数据
2024-11-19 03:19:52 +0800 CST
Golang 中你应该知道的 noCopy 策略
2024-11-19 05:40:53 +0800 CST
WebSocket在消息推送中的应用代码
2024-11-18 21:46:05 +0800 CST
JavaScript设计模式:观察者模式
2024-11-19 05:37:50 +0800 CST
网站日志分析脚本
2024-11-19 03:48:35 +0800 CST
Claude:审美炸裂的网页生成工具
2024-11-19 09:38:41 +0800 CST
程序员茄子在线接单