premage.js 实现预览本地上传图片

实时预览上传图片所用插件是 premage.js

参考网址: http://harryjoy.github.io/premage/


大致描述一下操作方式,选择图片上传后,premage.js会生成一个<img id='img-live-preview-id' >的标签,标签的地址是本地文件地址,具体如何生成不清楚,源码目前没有能力解析。


下面是具体过程:

1.所需资源

jquery.js   

premage.js  

        premage.css可选 --premage.js里面生成一些标签有用到该CSS文件


2.jsp 页面调用过程

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Img Live</title>

<link href="jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
<script src="jquery-1.10.2.js"></script>
<script src="jquery-ui-1.10.4.custom.min.js" type="text/javascript" ></script>
<script type="text/javascript" src="premage.js"></script>
<script>
$(document).ready(function() {
	var b = $("#imglive").premage();
});
</script>
</head>
<body>
<input type="file" name="imglive" id="imglive" />

</body>
</html>

3.图片上传新增<img >标签显示



4.一些说明

以下是生成<img>标签的源代码,如果有需求可以进行修改

		this.draw = function () {
			this.previewImage = $("<img />").addClass('preview-image').attr('src', this.options.default_image).attr('id', 'img-live-preview-id');
			this.setOptions();
		};


*学习中,如有错误之处请指点,3Q.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值