我作了一個二維碼的一個簽到功能css
經過JQuery來生成二維碼jquery
可是沒想到在IE9,10 以上都沒有問題canvas
而後客戶的機子上居然是IE8,app
還好找到了問題code
在IE8 下js報錯 getContext 找不到、blog
解決方案:修改jquery.qrcode.min.jsget
源碼:源碼
h = r.extend({}, { render: "canvas", width: 256, height: 256, typeNumber: -1, correctLevel: 2, background: "#ffffff", foreground: "#000000" }, h);
將table
render 的值改成 table
if ("canvas" == h.render) { a = new o(h.typeNumber, h.correctLevel); a.addData(h.text); a.make(); var c = document.createElement("canvas"); c.width = h.width; c.height = h.height; for (var d = c.getContext("2d"), b = h.width / a.getModuleCount(), e = h.height / a.getModuleCount(), f = 0; f < a.getModuleCount(); f++) for (var i = 0; i < a.getModuleCount(); i++) { d.fillStyle = a.isDark(f, i) ? h.foreground : h.background; var g = Math.ceil((i + 1) * b) - Math.floor(i * b), j = Math.ceil((f + 1) * b) - Math.floor(f * b); d.fillRect(Math.round(i * b), Math.round(f * e), g, j) } } else { a = new o(h.typeNumber, h.correctLevel); a.addData(h.text); a.make(); c = r("<table></table>").css("width", h.width + "px").css("height", h.height + "px").css("border", "0px").css("border-collapse", "collapse").css("background-color", h.background); d = h.width / a.getModuleCount(); b = h.height / a.getModuleCount(); for (e = 0; e < a.getModuleCount(); e++) { f = r("<tr></tr>").css("height", b + "px").appendTo(c); for (i = 0; i < a.getModuleCount(); i++) r("<td></td>").css("width", d + "px").css("background-color", a.isDark(e, i) ? h.foreground : h.background).appendTo(f) } }
你們能夠看到代碼:若 render 的值爲canvas,那麼則會調用getContext ,那麼IE8會出錯,class
因此咱們這裏使用table
固然,更改成table 以後,須要修改修改樣式,不然會很難看...
#code,#code table{text-align:center;margin:0 auto} #code table,#code th,#code td{font-size:1px;overflow: hidden;padding:0}
code 爲二維碼所放至的div的 id
謝謝