Generate a QR code and a QR code with Parameters
This article describes a jquery-based QR code generation plug-in qrcode. You can call this plug-in on the page to generate the corresponding QR code.
1. First, add the jquery library file and qrcode plug-in to the page.
<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.qrcode.min.js"></script>
2. Add a div in the page layout
<Div class = "modal-body" id = "qrCode"> var str = "http: //" + location. host + "/ActivityDetail.html? Id = "+ row. activityGuid + "& isMail =" + row. isMail + ""; $ ("# qrCode "). empty (); $ ('# qrCode '). qrcode (str); // $ ('# qrCode '). qrcode ("http://www.helloweba.com"); // any string
4. During the experiment, we found that the two-dimensional code could not recognize Chinese content. We found that jquery-qrcode was converted using charCodeAt. And this method will get its Unicode encoding by default, if there is Chinese content, in the generation of the QR code before the string to the UTF-8, and then generate a QR code. You can use the following functions to convert Chinese strings:
function toUtf8(str) { var out, i, len, c; out = ""; len = str.length; for(i = 0; i < len; i++) { c = str.charCodeAt(i); if ((c >= 0x0001) && (c <= 0x007F)) { out += str.charAt(i); } else if (c > 0x07FF) { out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F)); out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F)); out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); } else { out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F)); out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); } } return out; }
You can directly write this method into the referenced plug-in and call it later. As follows:
Var str = toUtf8 ("2017 rooster success! "); $ ('# QrCode'). qrcode (str );