$("#btn").click(function(){
var width = 300;
//var height = 500;
var type = "png";
var scaleBy = 3; //缩放比例
var canvas = document.createElement('canvas');
canvas.width = width * scaleBy;
//canvas.height = height * scaleBy;
canvas.style.width = width * scaleBy + 'px';
//canvas.style.height = height * scaleBy + 'px';
var context = canvas.getContext('2d');
context.scale(scaleBy, scaleBy);
html2canvas($("#container"), {
useCORS: true, //(图片跨域相关)
allowTaint: false, //允许跨域(图片跨域相关)
taintTest: true, //是否在渲染前测试图片
canvas:canvas,
width: width,
//height: height,
onrendered: function(canvas) {
$('.showImg').attr('src', canvas.toDataURL("image/png", 1.0));
}