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

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

推荐文章

IP地址获取函数
2024-11-19 00:03:29 +0800 CST
PHP 8.4 中的新数组函数
2024-11-19 08:33:52 +0800 CST
php curl并发代码
2024-11-18 01:45:03 +0800 CST
js生成器函数
2024-11-18 15:21:08 +0800 CST
html5在客户端存储数据
2024-11-17 05:02:17 +0800 CST
前端代码规范 - Commit 提交规范
2024-11-18 10:18:08 +0800 CST
PHP 的生成器,用过的都说好!
2024-11-18 04:43:02 +0800 CST
Golang 中应该知道的 defer 知识
2024-11-18 13:18:56 +0800 CST
Vue3中的Store模式有哪些改进?
2024-11-18 11:47:53 +0800 CST
支付宝批量转账
2024-11-18 20:26:17 +0800 CST
Rust async/await 异步运行时
2024-11-18 19:04:17 +0800 CST
mysql删除重复数据
2024-11-19 03:19:52 +0800 CST
一文详解回调地狱
2024-11-19 05:05:31 +0800 CST
设置mysql支持emoji表情
2024-11-17 04:59:45 +0800 CST
使用Python实现邮件自动化
2024-11-18 20:18:14 +0800 CST
解决python “No module named pip”
2024-11-18 11:49:18 +0800 CST
黑客帝国代码雨效果
2024-11-19 01:49:31 +0800 CST
Go 语言实现 API 限流的最佳实践
2024-11-19 01:51:21 +0800 CST
程序员茄子在线接单