<script src="~/Content/lib/ewm/jquery.qrcode.js"></script> <script src="~/Content/lib/ewm/utf.js"></script> <div id="ewmdiv" style="margin-left:35%;"></div> <a onclick="dcEWM()" style="margin-left: 20%;">导出二维码</a> <script type="text/javascript"> var ewm = "二维码内容"; function init(url) { $("#ewmdiv").html(""); $("#ewmdiv").qrcode({ render: "canvas", text: url, 200, height: 200, background: "#ffffff", //二维码的后景色 foreground: "#000000"//, //二维码的前景色 src: '/img/ewm.png' //二维码中间的图片 }); } init(ewm); var name="二维码名称"; function dcEWM() { init(ewm); var now =getDate(); var img = document.getElementById("ewmdiv").getElementsByTagName("canvas"); var alink = document.createElement("a"); alink.href = img[0].toDataURL("image/png"); alink.download = name + now + ".png"; alink.click(); } function getDate() { var myDate = new Date(); //获取当前年 var year = myDate.getFullYear(); //获取当前月 var month = myDate.getMonth() + 1; //获取当前日 var date = myDate.getDate(); var h = myDate.getHours(); //获取当前小时数(0-23) var m = myDate.getMinutes(); //获取当前分钟数(0-59) var s = myDate.getSeconds(); //获取当前时间 now = year + "" + month + date + h + m + s; } </script>