jquery二維碼

來源:互聯網
上載者:User

標籤:create   module   email   content   code   date   cli   replace   upd   

這裡可以調用一個jq-qrcode庫,然後根據參數往裡面傳內容即可,本人當時做的是一個名片系統,所以可以產生一個vcf檔案在PC端。

具體專案檔請見:https://github.com/marhovey/QRcode;

jq-qrcode直接存取:https://github.com/jeromeetienne/jquery-qrcode;

1、產生名片二維碼:

function createvcf() {
  $(".qrBox").css({display:"block"});
  var a,
  c = $("#name").html().replaceAll(" ", ""),
  d = $("#title").html().replaceAll(" ", ""),
  e = $("#adr").html().replaceAll(" ", ""),
  f = $("#org").html().replaceAll(" ", ""),
  g = $("#cell").html().replaceAll(" ", ""),
  h = $("#home").html().replaceAll(" ", ""),
  i = $("#url").html().replaceAll(" ", ""),
  j = $("#email").html().replaceAll(" ", "");
  e=e.slice(0,e.search("<img"));
  a = "BEGIN:VCARD", a += "\r\nN:"+ c, d && (a += "\r\nTITLE:" + d), e && (a += "\r\nADR;WORK:;;" + e + ";;;;"), f && (a += "\r\nORG:" + f), g && (a += "\r\nTEL;CELL,VOICE:" + g), h && (a += "\r\nTEL;WORK,VOICE:" + h), i && (a += "\r\nURL;WORK:" + i), j && (a += "\r\nEMAIL;INTERNET,HOME:" + j), a += "\r\nEND:VCARD", $("#qrcode").empty().qrcode({
    render: "image",
    ecLevel: "0" == $("#mode").val() ? "L": "H",
    size: 300,
    background: "#fff",
    fill: $("#fill").val(),
    radius: $("#radius").val(),
    mode: 1 * $("#mode").val(),
    fontcolor: $("#fontcolor").val(),
    label: c,
    text: a
  })
  }
  String.prototype.replaceAll = function(a, b) {
  return this.replace(new RegExp(a.replace(/([\(\)\[\]\{\}\^\$\+\-\*\?\.\"\‘\|\/\\])/g, "\\$1"), "ig"), b)
  };
  document.getElementById(‘btn‘).onclick=function(){
  createvcf();
}

2、產生網域名稱二維碼:

(function () {
  ‘use strict‘;

  var jq = window.jQuery;
  var guiValuePairs = [
    [‘size‘, ‘px‘],
    [‘minversion‘, ‘‘],
    [‘quiet‘, ‘ modules‘],
    [‘radius‘, ‘%‘],
    [‘msize‘, ‘%‘],
    [‘mposx‘, ‘%‘],
    [‘mposy‘, ‘%‘]
  ];

  function updateGui() {
    jq.each(guiValuePairs, function (idx, pair) {
      var $label = jq(‘label[for="‘ + pair[0] + ‘"]‘);
      $label.text($label.text().replace(/:.*/, ‘: ‘ + jq(‘#‘ + pair[0]).val() + pair[1]));
    });
  }
  function updateQrCode() {
    var options = {
      render: "image",
      ecLevel: "H",
      minVersion: parseInt("1", 10),

      fill: "#333",
      background: "#fff",

      text: document.URL,

      //大小
      size: parseInt("150", 10),

      radius: parseInt("0", 10) * 0.01,
      quiet: parseInt("1", 10),

      mode: parseInt("0", 10),

      image: jq(‘#img-buffer‘)[0]
    };

   jq(‘#erwm‘).empty().qrcode(options);
  }

  function update() {
    updateGui();
    updateQrCode();
  }

  function onImageInput() {
    var input = jq(‘#image‘)[0];
    if (input.files && input.files[0]) {
      var reader = new FileReader();
      reader.onload = function (event) {
        jq(‘#img-buffer‘).attr(‘src‘, event.target.result);
        jq(‘#mode‘).val(‘4‘);
        setTimeout(update, 250);
    };
    reader.readAsDataURL(input.files[0]);
    }
  }
  function init() {
    jq(‘#image‘).on(‘change‘, onImageInput);
    jq(window).load(update);
    update();
   }
  jq(init);
}());

3、產生vcf檔案:

<?php
  header("Content-type: text/html; charset=utf-8");
  $name=$_POST["name"];
  $title=$_POST["title"];
  $adr=$_POST["adr"];
  $org=$_POST["org"];
  $cell=$_POST["cell"];
  $home=$_POST["home"];
  $url=$_POST["url"];
  $email=$_POST["email"];
  $myfile=fopen("index.vcf","w");
  $txt="BEGIN:VCARD\r\n"."N:".$name."\r\nORG:".$org."\r\nTITLE:".$title."\r\nADR;TYPE=WORK:;;".$adr."\r\nTEL;TYPE=CELL,VOICE:".$cell."\r\nTEL;TYPE=WORK,VOICE:".$home."\r\nEMAIL;TYPE=PREF,INTERNET:".$email."\r\nEND:VCARD";
  fwrite($myfile, $txt);
  fclose(myfile);
?>

jquery二維碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.