JQuery IE8 找不到getContext屬性,相容性問題

來源:互聯網
上載者:User

標籤:round   document   code   flow   相容   二維   sharp   性問題   canvas   

我做了一個二維碼的一個簽到功能

通過JQuery來產生二維碼

但是沒想到在IE9,10 以上都沒有問題

然後客戶的機子上竟然是IE8,

還好找到了問題

在IE8  下js報錯  getContext 找不到、

解決方案:修改jquery.qrcode.min.js

源碼:

 h = r.extend({}, {            render: "canvas",            width: 256,            height: 256,            typeNumber: -1,            correctLevel: 2,            background: "#ffffff",            foreground: "#000000"        }, h);

 將

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會出錯,

所以我們這裡使用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

 

 

謝謝

 

 

 

 


 

 

JQuery IE8 找不到getContext屬性,相容性問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.