前提:之前用了別人網站的api來實現生成二維碼,亮哥說不行,這樣太依賴別人的,真的實現不了才這么做。
這次,我就選擇了別人開源的文件進行調用,只要加載一個小js文件,再用它的語法即可。
下載qrcodejs URL:http://davidshimjs.github.io/qrcodejs/
在頁面中引用jq和qrcodejs兩個文件
html頁面
<html>
<head>
<title>demo</title>
</head>
<script type="text/javascript" src="./js/jquery.js"></script>
<script type="text/javascript" src="./js/qrcode.min.js"></script>
<body>
<div id="qrcode"></div>
<input type="button" value="按鈕" id="hit"/>
</body>
<script type="text/javascript">
var qrcode = new QRCode("qrcode", {
text: 'http://www.baidu.com', //URL地址
width: 260,
height: 260,
colorDark: '#000', //二維碼顏色
colorLight: "#ffffff" //背景顏色
});
$('#hit').click(function(){
qrcode.clear(); // clear the code.
qrcode.makeCode("http://naver.com"); // make another code.
});
</script>
</html>
"qrcode" 為一個標簽的id,執行后會在標簽中插入一個cansave和img標簽
img的src為 base64值
————————————————
版權聲明:本文為CSDN博主「韓師學子--小倪」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/xiao__jia__jia/article/details/89045206