js中常混淆的

Window innerWidth 和 innerHeight 属性(不包含工具条和滚动条)
innerheight 返回窗口的文档显示区的高度。
innerwidth 返回窗口的文档显示区的宽度。
使用 outerWidth 和 outerHeight 属性获取加上工具条与滚动条窗口的宽度与高度。
在这里插入图片描述

element.offsetHeight
返回任何一个元素的高度包括边框和填充,但不包括边距
在这里插入图片描述
element.poffsetWidth
返回元素的快递,包括边框和填充,但不包括边距
在这里插入图片描述

element.offsetTop
返回当前元素的相对垂直偏移位置的偏移容器(相对于doc来说的)
在这里插入图片描述

element.offsetLeft
返回当前元素的相对水平偏移位置的偏移容器(相对于doc来说的)
在这里插入图片描述

图片上传问题的解决方式,如果是图片在本地的话,而不是别的服务器那边的就可以用js下载
var alink = document.createElement(“a”);
alink.href = img;
alink.download = img;
alink.click();
如果资源在别的服务器那边的话,只能用后台代码写,如下
js :
window.location.href = “/api/product/download?filePath=”+ img +"&id="+itemId
java后台代码:
在这里插入图片描述
/**
* 文件下載的處理
* @param request
* @param response
* @throws IOException
*/

public static void downLoadFile(HttpServletRequest request, HttpServletResponse response) throws  IOException{
    String filePath = request.getParameter("filePath");
    int suffixIndex = filePath.lastIndexOf("/");
   // String fileName = filePath.substring(suffixIndex + 1,filePath.length());
    String fileName = request.getParameter("id");
    //读取字符编码
    String encoding = "UTF-8";
    //设置响应
    response.setCharacterEncoding(encoding);
    response.setContentType("text/html; charset=" + encoding);
    response.setHeader("Pragma","public");
    response.setHeader("Cache-Control","max-age=30");
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".png");
    //作出响应
    URL url = new URL(filePath);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    InputStream inStream = conn.getInputStream();
    byte[] buf = new byte[1024 * 10];
    OutputStream os = response.getOutputStream();
    int len = 0;
    if(conn.getResponseCode() == 200) {
        while ((len = inStream.read(buf)) != -1) {
            os.write(buf,0,len);
            os.flush();
        }
        closeStream(inStream,os);
    }
}

/**
 *   关闭流字节流的操作
 * @param in
 * @param out
 */

public static void closeStream(InputStream in,OutputStream out){
    try {
        if(in != null){
            in.close();
        }
        if(out != null){
            out.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值