在页面上生成二维码

    xiaoxiao2026-04-04  3

    <!doctype html> <html> <head> <style> body{ margin: 0; padding: 0; } /*qrcode*/ #qrcode{ margin: 0 auto; } </style> </head> <body> <input id='text' type='text' value="http://www.lcfbk.top" style="width:80%"> <div id="qrcode" style="width:100px; height:100px; margin-top:15px;"></div> </body> <script src="http://ossweb-img.qq.com/images/js/zepto/zepto-1.1.6.min.js"></script> <script src="js/qrcode.js"></script> <script> var create_ewm = function() { //1、创建qrcode对象, width 和 height 是最后显示二维码图片的宽和高 var qrcode = new QRCode(document.getElementById("qrcode"), { width : 200, height : 200 }); //2、判断输入框是否有地址,如果有则生成二维码 function makeCode () { var elText = document.getElementById("text"); if (!elText.value) { alert("请输入一个url地址!"); elText.focus(); return; } qrcode.makeCode(elText.value); } //3、给输入框添加事件,输入框失去焦点或者用户按enter键都调用makeCode方法 $("#text"). on("blur", function () { makeCode(); }). on("keydown", function (e) { if (e.keyCode == 13) { makeCode(); } }); makeCode(); }(); </script> </html>

     

    源码下载地址 :http://download.csdn.net/detail/qq408896436/9604488

    转载请注明原文地址: https://ju.6miu.com/read-1308505.html
    最新回复(0)