以下代碼有問題,親測會報error, 看了下make 函數的括號都沒有對上。
正確做法,到以下官網上去下載一個最新版的文件就可以了。
https://github.com/KeeeX/qrcodejs
============================================================================
近日在開發過程中需要爲頁面動態生成一個二維碼信息,由於這個二維碼中包含了很多文字,字母以及符號,測試過程中發現有些二維碼會報錯,因爲二維碼內容太多了,沒辦法顯示。後來在GitHub中找到了解決辦法。
這是源碼中修改前的內容:
make:function(){this.makeImpl(false,this.getBestMaskPattern());} QRCode.prototype.makeCode = function (sText) { this._oQRCode = new QRCodeModel(_getTypeNumber(sText, this._htOption.correctLevel), this._htOption.correctLevel); this._oQRCode.addData(sText); this._oQRCode.make(); this._el.title = sText; this._oDrawing.draw(this._oQRCode); this.makeImage(); };
這是修改後的內容:
make:function(){ if(this.typeNumber<1){ var typeNumber = 1; for (typeNumber = 1;typeNumber<40;typeNumber++){ var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel); var buffer = new QRBitBuffer();var totalDataCount = 0; for(var i=0;i<rsBlocks.length;i++) { totalDataCount+=rsBlocks[i].dataCount; } for (var i = 0; i < this.dataList.length; i++) { var data = this.dataList[i]; buffer.put(data.mode, 4); buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber)); data.write(buffer);} if (buffer.getLengthInBits() <= totalDataCount * 8)break;} this.typeNumber = typeNumber; } QRCode.prototype.makeCode = function (sText) { this._oQRCode = new QRCodeModel(-1, this._htOption.correctLevel); this._oQRCode.addData(sText); this._oQRCode.make(); this._el.title = sText; this._oDrawing.draw(this._oQRCode); this.makeImage(); };
出自: https://www.cnblogs.com/Miracle-ZLZ/p/7723857.html