<script>
/**
* 将图片转换为Base64
*/
function image2Base64(img) {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
var dataURL = canvas.toDataURL("image/png");
return dataURL;
}
$("#tijiao").click(function(){
var imgurl = $(".z_addImg img").attr("src"); //获取的图片路径
var img = new Image();
img.src=imgurl;
var base64 = image2Base64(img);
alert(base64); //弹出base64图片字符串看看,如果很长很长就成功啦
})
</script>