EMlog侧边栏增加新浪图床
时间:2020-08-01 阅读:244
教程截图
教程简介
为EMLOG系统侧边栏增加图床代码 今天我们用的是新浪接口不知道接口以后会不会和先算用着打开侧边栏新建侧边栏复制我们的代码在保存 下来侧边栏设置显示这个侧边栏
新浪代码
<div class="momll"> <style> momll-img{max-width:80%;display:block} #选图{position:absolute;z-index:1;cursor:pointer;opacity:0} #box,#选图{background:#b485e2;color:#FFF;display:block;height:40px;line-height:30px;text-align:center} </style> <input type="file" id="选图"> <div id="box">选择或拖拽图像进行上传</div> <img id="图片" style="width:100%"> <p id="文本" style="word-wrap:break-word"></p> <script src="https://www.mom1.cn/m1/mom11.js"></script> <script> 选图.onchange=function(){ if(!this.files||!this.files[0]) return alert('选取文件出错!') var 图片文件=this.files[0] if(图片文件.type.indexOf('image')!=0) return alert('这不是一个图像或音频!') UP(图片文件,function(pid){ 文本.innerHTML= 图片.src='https://ww2.sinaimg.cn/large/'+pid+ '.jpg' },function(){ alert('上传文件出错了!') },function(进度){ 文本.innerHTML=进度*100+'%' }) } </script></div> <script> var UP=function(o,success,error,upload,x,file,A){ if(typeof success=='function') file=o; else{ if(!o.file) return console.log('并没有传入需要上传的文件') if(A=o.success) success=A if(A=o.upload) upload=A if(A=o.error) error=A } x=new XMLHttpRequest() x.open('POST','https://x.mouto.org/wb/x.php?up&_r='+Math.random(),1) if(upload) x.upload.onprogress=function(e){ upload(e.loaded/e.total) } x.onload=function(r){ r=JSON.parse(x.responseText) if(r.error&&error) return error(r.error) if(r.pid&&success) return success(r.pid) } x.send(file) }</script>
网友评论