js实例教程-利用jquery包将字符串生成二维码图片

发布时间:2018-12-08 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了js实例教程-利用jquery包将字符串生成二维码图片脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

将一个字符串(可以是中文,在生成二维码图片之前将中文转码)生成二维码图片,如果想要带LOG的二维码,可以在生成后的二维码中间部位自己添加一个小log,log图片不要太大,不然就扫描不出内容了。

. 代码如下:


<htML XMlns="https://www.w3.org/1999/xhtml">
<head>
<tITle></title>
<script src="js/jquery-1.8.3.js" tyPE="text/javascript"></script>
<script src="js/qrcode.js" type="text/javascript"></script>
<script src="js/jquery.qrcode.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#BT").bind("click", function () {
text = $("#text").val();
$("#p_p").qrcode(utF16to8(text));

})
})
function utf16to8(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) &amp; 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;
}
</script>
</head>
<body>
<input type="text" id="text" />
<input type="button" value="shengc" id="bt" />
<p id="p_p" style="width:400px;height:400px;border:1px solid #000;"></p>
</body>
</html>


这里引用了三个js包,其中一个是jquery包,这个随便版本,另外两个就是画二维码用的js包了。

将一个字符串(可以是中文,在生成二维码图片之前将中文转码)生成二维码图片,如果想要带log的二维码,可以在生成后的二维码中间部位自己添加一个小log,log图片不要太大,不然就扫描不出内容了。

. 代码如下:


<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="js/jquery-1.8.3.js" type="text/javascript"></script>
<script src="js/qrcode.js" type="text/javascript"></script>
<script src="js/jquery.qrcode.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#bt").bind("click", function () {
text = $("#text").val();
$("#p_p").qrcode(utf16to8(text));

})
})
function utf16to8(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;
}
</script>
</head>
<body>
<input type="text" id="text" />
<input type="button" value="shengc" id="bt" />
<p id="p_p" style="width:400px;height:400px;border:1px solid #000;"></p>
</body>
</html>


这里引用了三个js包,其中一个是jquery包,这个随便版本,另外两个就是画二维码用的js包了。

觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦! js技巧,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的js实例教程-利用jquery包将字符串生成二维码图片全部内容,希望文章能够帮你解决js实例教程-利用jquery包将字符串生成二维码图片所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。