<script type="text/javascript" src="js/jquery.qrcode.min.js"></script>
<div id="code"></div>
<script>
$(function() {
makeQr("今晚撸",100,100);
});
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;
}
function makeQr(str,width,height){//二维码的内容,宽,高
$("#code").qrcode({
width: width,
height:height,
text:toUtf8(str)
});
}
</script>
本文介绍了一种利用jQuery插件在网页上生成二维码的方法。通过引入必要的JavaScript文件,并定义makeQr函数来设置二维码的内容、宽度和高度。文章提供了完整的示例代码。
2508

被折叠的 条评论
为什么被折叠?



