使用JavaScript生成二維碼教程-附qrcodejs中文文檔

使用javascript生成二維碼 依賴jqueryjavascript

須要使用到的庫html


https://github.com/davidshimjs/qrcodejsjava

DIV

<div id="qrcode"></div>

javascript

var qrcode = new QRCode("qrcode");
 
  qrcode.makeCode("http://www.fengkaichang.com");

至此一個簡單的二維碼就生成了jquery

image

接下來咱們就詳細瞭解一下這個庫到底爲咱們提供了哪些參數配置和方法git

配置

new  QRCode(element,option)
名稱 默認值 類型 說明
element - string 顯示二維碼的元素或該元素的 ID
option objec 參數配置
名稱 默認值 類型 說明
text - string 須要生成的二維碼內容
width 256 number 圖像寬度
height 256 number 圖像高度
colorDark "#000000" string 前景色
colorLight "#ffffff" string 背景色
correctLevel QRCode.CorrectLevel.L 容錯級別

容錯級別有github

QRCode.CorrectLevel.L
QRCode.CorrectLevel.M
QRCode.CorrectLevel.Q
QRCode.CorrectLevel.H
var qrcode = new  QRCode(element), {
	text: "www,fengkaichang.com",
	width: 150,
	height: 150,
	colorDark : "#000000",
	colorLight : "#ffffff",
	typeNumber:4,
	correctLevel : QRCode.CorrectLevel.H
});

API方法

qrcode.makeCode(text)	//設置二維碼內容
qrcode.clear() //清除二維碼。

相關信息 GitHub 中文文檔code


更多內容請訪問個人我的博客www.fengkaichang.comhtm

相關文章
相關標籤/搜索