根据URL地址生成二维码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiao__jia__jia/article/details/89045206

                     根据URL地址生成二维码


前提:之前用了别人网站的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值

猜你喜欢

转载自blog.csdn.net/xiao__jia__jia/article/details/89045206
今日推荐