首选,你得将jquery和jquery.qrcode导入到文件中,记住了,jquery.qrcode是基于jquery的哦,要放在后面(。◕ˇ∀ˇ◕)
1 2 | <script src= "//cdn.bootcss.com/jquery/3.1.1/jquery.min.js" ></script> <script src= "//cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js" ></script> |
然后,我们在页面要显示二维码的地方输入这些代码
最后,我们调用qrcode插件。(qrcode支持canvas和table两种方式进行图片渲染,默认使用canvas方式,效率最高,当然要浏览器支持html5。)直接调用如下:
1 2 3 | $(document).ready(function(){ $('#code').qrcode("http://www.baidu.com"); }) |
如果说你要支持像IE这种反人类的浏览器的话,就要使用table方式啦_(:3 」∠)_
1 2 3 4 5 6 7 8 | $(document).ready(function(){ $("#code").qrcode({ render: "table", //table方式 width: 100, //宽度 height:100, //高度 text: "http://www.cnblogs.com/momozjm/" //任意内容 }); }) |