最新消息:欢迎访问刘磊博客

js代码里链接生成二维码

javascript 飞翔的mouse 53浏览

方法一:用jquery的二维码生成js库

html里代码:


<!DOCTYPE html>
<html>
<head>
<!–引入jquery,jquery.qrcode–>
<script type=’text/javascript’src=’http://cdn.staticfile.org/jquery/2.1.1/jquery.min.js’></script>
<script type=”text/javascript”src=”http://cdn.staticfile.org/jquery.qrcode/1.0/jquery.qrcode.min.js”></script>
</head>
<body>
<div id = “qrid”></div>
</body>
<script>
$(function(){
var qrstr = “https://www.xxx.com/xxx/xxx”;
$(‘#qrid’).qrcode(qrstr);//不指定二维码大写
$(‘#qrid’).qrcode({width: 280,height: 280,text: qrstr});//指定二维码大小
});
</script>
</html>

方法二:用原生js的代码生成器,也需要js库
git下载路径:https://github.com/davidshimjs/qrcodejs
runoob更详细教程:http://www.runoob.com/w3cnote/javascript-qrcodejs-library.html

<!DOCTYPE html>
<html>
<head>
<script type=’text/javascript’src=’http://cdn.staticfile.org/jquery/2.1.1/jquery.min.js’></script>
<script type=”text/javascript”src=”js/qrcode.min.js”></script>
</head>
<body>
<div id = “qrid”></div>
</body>
<script>
$(function(){
var qrstr = “https://www.xxx.com/xxx/xxx”;
new QRCode(document.getElementById(“qrid”), qrstr);
});
</script>
</html>

转载请注明:刘磊博客 » js代码里链接生成二维码