{"id":476,"date":"2023-02-25T13:48:08","date_gmt":"2023-02-25T05:48:08","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=476"},"modified":"2023-04-29T20:54:11","modified_gmt":"2023-04-29T12:54:11","slug":"front-end-qrcode-js-generate-qr-code-plugin","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/front-end-qrcode-js-generate-qr-code-plugin\/","title":{"rendered":"\u524d\u7aefQRCode.js\u751f\u6210\u4e8c\u7ef4\u7801\u63d2\u4ef6"},"content":{"rendered":"<p>\u672c\u6587\u7528\u4e8e\u63a8\u8350\u4e00\u6b3e\u5f88\u597d\u7528\u7684\u4e8c\u7ef4\u7801\u751f\u6210\u63d2\u4ef6QRCode.js\uff0c\u6d4b\u8bd5\u4f7f\u7528\u65b9\u4fbf\u4e14\u7b80\u5355\u3002 \u5176\u5b9e\u5b98\u65b9\u5c31\u6709\u5f88\u597d\u7684\u6587\u6863\uff0c\u8fd9\u91cc\u53ea\u662f\u505a\u4e00\u4e2a\u6211\u5de5\u4f5c\u7684\u8bb0\u5f55\u548c\u603b\u7ed3\u3002<\/p>\n<h2>\u4ecb\u7ecd<\/h2>\n<p>Github\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/davidshimjs\/qrcodejs\">https:\/\/github.com\/davidshimjs\/qrcodejs<\/a><\/p>\n<p><!-- more --><\/p>\n<ul>\n<li>\u4e3b\u8981\u4f7f\u7528canvas\u5b9e\u73b0<\/li>\n<li>\u539f\u751f\u4ee3\u7801\uff0c\u65e0\u9700\u4f9d\u8d56<\/li>\n<li>\u517c\u5bb9\u6027\u4e5f\u5f88\u597d\uff0cIE6~10, Chrome, Firefox, Safari, Opera, Mobile Safari, Android, Windows Mobile, ETC.<\/li>\n<\/ul>\n<h2>\u4f7f\u7528<\/h2>\n<h3>\u5f15\u5165js\u6587\u4ef6<\/h3>\n<pre><code class=\"language-html\">&lt;script src=&quot;qrcode.js&quot;&gt;&lt;\/script&gt;<\/code><\/pre>\n<h3>\u5b9a\u4e49\u627f\u8f7d\u4e8c\u7ef4\u7801\u6807\u7b7e<\/h3>\n<pre><code class=\"language-html\">&lt;div id=&quot;qrcode&quot;&gt;&lt;\/div&gt;<\/code><\/pre>\n<h3>js\u8c03\u7528<\/h3>\n<h4>\u7b80\u5355\u8c03\u7528<\/h4>\n<pre><code class=\"language-javascript\">new QRCode(document.getElementById(&#039;qrcode&#039;), &#039;http:\/\/www.appblog.cn&#039;);<\/code><\/pre>\n<h4>\u8bbe\u7f6e\u53c2\u6570\u8c03\u7528<\/h4>\n<pre><code class=\"language-javascript\">var qrcode = new QRCode(&#039;qrcode&#039;, {\n    text: &#039;http:\/\/www.appblog.cn&#039;,\n    width: 256,\n    height: 256,\n    colorDark: &#039;#000000&#039;,\n    colorLight: &#039;#ffffff&#039;,\n    correctLevel: QRCode.CorrectLevel.H\n});<\/code><\/pre>\n<h2>\u53c2\u6570API<\/h2>\n<h3>QRCode\u53c2\u6570<\/h3>\n<pre><code class=\"language-javascript\">new QRCode(element, option)<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u540d\u79f0<\/th>\n<th style=\"text-align: center;\">\u9ed8\u8ba4\u503c<\/th>\n<th style=\"text-align: center;\">\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\"><code>element<\/code><\/td>\n<td style=\"text-align: center;\">&#8211;<\/td>\n<td style=\"text-align: center;\">\u627f\u8f7d\u4e8c\u7ef4\u7801\u7684DOM\u5143\u7d20\u7684ID<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><code>option<\/code><\/td>\n<td style=\"text-align: center;\">&#8211;<\/td>\n<td style=\"text-align: center;\">\u53c2\u6570\u8bbe\u7f6e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Option\u53c2\u6570<\/h3>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u540d\u79f0<\/th>\n<th style=\"text-align: center;\">\u9ed8\u8ba4\u503c<\/th>\n<th style=\"text-align: center;\">\u8bf4\u660e<\/th>\n<th style=\"text-align: center;\">\u5907\u6ce8<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\"><code>text<\/code><\/td>\n<td style=\"text-align: center;\">&#8211;<\/td>\n<td style=\"text-align: center;\">\u4e8c\u7ef4\u7801\u627f\u8f7d\u7684\u4fe1\u606f<\/td>\n<td style=\"text-align: center;\">\u4e2d\u6587\u4f7f\u7528encodeURIComponent\u8fdb\u884c\u7f16\u7801<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><code>width<\/code><\/td>\n<td style=\"text-align: center;\">256<\/td>\n<td style=\"text-align: center;\">\u4e8c\u7ef4\u7801\u5bbd\u5ea6<\/td>\n<td style=\"text-align: center;\">\u5355\u4f4d\u50cf\u7d20\uff08\u767e\u5206\u6bd4\u4e0d\u884c\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><code>height<\/code><\/td>\n<td style=\"text-align: center;\">256<\/td>\n<td style=\"text-align: center;\">\u4e8c\u7ef4\u7801\u9ad8\u5ea6<\/td>\n<td style=\"text-align: center;\">\u5355\u4f4d\u50cf\u7d20\uff08\u767e\u5206\u6bd4\u4e0d\u884c\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><code>colorDark<\/code><\/td>\n<td style=\"text-align: center;\">&#8216;#000000&#8217;<\/td>\n<td style=\"text-align: center;\">\u4e8c\u7ef4\u7801\u524d\u666f\u8272<\/td>\n<td style=\"text-align: center;\">\u82f1\u6587\\\u5341\u516d\u8fdb\u5236\\rgb\\rgba\\transparent\u90fd\u53ef\u4ee5<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><code>colorLight<\/code><\/td>\n<td style=\"text-align: center;\">&#8216;#ffffff&#8217;<\/td>\n<td style=\"text-align: center;\">\u4e8c\u7ef4\u7801\u80cc\u666f\u8272<\/td>\n<td style=\"text-align: center;\">\u82f1\u6587\\\u5341\u516d\u8fdb\u5236\\rgb\\rgba\\transparent\u90fd\u53ef\u4ee5<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><code>correctLevel<\/code><\/td>\n<td style=\"text-align: center;\"><code>QRCode.CorrectLevel.L<\/code><\/td>\n<td style=\"text-align: center;\">\u5bb9\u9519\u7ea7\u522b<\/td>\n<td style=\"text-align: center;\">\u7531\u4f4e\u5230\u9ad8<br \/><code>QRCode.CorrectLevel.L<\/code><br \/><code>QRCode.CorrectLevel.M<\/code><br \/><code>QRCode.CorrectLevel.Q<\/code><br \/><code>QRCode.CorrectLevel.H<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>API\u63a5\u53e3<\/h3>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u540d\u79f0<\/th>\n<th style=\"text-align: center;\">\u53c2\u6570<\/th>\n<th style=\"text-align: center;\">\u8bf4\u660e<\/th>\n<th style=\"text-align: center;\">\u4f7f\u7528<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\"><code>clear<\/code><\/td>\n<td style=\"text-align: center;\">&#8211;<\/td>\n<td style=\"text-align: center;\">\u6e05\u9664\u4e8c\u7ef4\u7801<\/td>\n<td style=\"text-align: center;\"><code>qrcode.clear()<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><code>makeCode<\/code><\/td>\n<td style=\"text-align: center;\">string<\/td>\n<td style=\"text-align: center;\">\u66ff\u6362\u4e8c\u7ef4\u7801<br \/>\uff08\u53c2\u6570\u91cc\u9762\u662f\u65b0\u7684\u4e8c\u7ef4\u7801\u5185\u5bb9\uff09<\/td>\n<td style=\"text-align: center;\"><code>qrcode.makeCode(&#039;new content&#039;)<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-javascript\">var qrcode = new QRCode(&#039;qrcode&#039;,{\n    &#039;text&#039;:&#039;content&#039;,\n    &#039;width&#039;:256,\n    &#039;height&#039;:256,\n    &#039;colorDark&#039;:&#039;red&#039;,\n    &#039;colorLoght&#039;:&#039;transparent&#039;,\n    &#039;correctLevel&#039;:QRCode.CorrectLevel.H\n})\n\nqrcode.clear();\nqrcode.madkCode(&#039;new content&#039;);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u7528\u4e8e\u63a8\u8350\u4e00\u6b3e\u5f88\u597d\u7528\u7684\u4e8c\u7ef4\u7801\u751f\u6210\u63d2\u4ef6QRCode.js\uff0c\u6d4b\u8bd5\u4f7f\u7528\u65b9\u4fbf\u4e14\u7b80\u5355\u3002 \u5176\u5b9e\u5b98\u65b9\u5c31\u6709\u5f88\u597d\u7684\u6587\u6863\uff0c\u8fd9\u91cc\u53ea [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[161],"class_list":["post-476","post","type-post","status-publish","format-standard","hentry","category-frontend-basic","tag-qrcode"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=476"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/476\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}