js文件2

调用:
链接:

http://www.helloweba.com/view-blog-226.html

<script type="text/javascript">
window.onload=function(){
    $('#code').qrcode("http://cms.dorago.cn/login.jsp"); //需要跳转的路径
//或者下边的方法
//    $("#code").qrcode({ 
//      render: "table", //table方式 
//      width: 200, //宽度 
//      height:200, //高度 
//      text: "nihao" //任意内容 
//  }); 
 }

</script>


<div style="padding-top: 50px;">用户注册二维码:</div>                   
<div id="code" style="margin-top: 25px;"></div> <!-- 此处是生成二维码的地方-->

识别中文:

function toUtf8(str) {    
    var out, i, len, c;    
    out = "";    
    len = str.length;    
    for(i = 0; i < len; i++) {    
        c = str.charCodeAt(i);    
        if ((c >= 0x0001) && (c <= 0x007F)) {    
            out += str.charAt(i);    
        } else if (c > 0x07FF) {    
            out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));    
            out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));    
            out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));    
        } else {    
            out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));    
            out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));    
        }    
    }    
    return out;    
} 

//调用:
var str = toUtf8("钓鱼岛是中国的!"); 
$('#code').qrcode(str); 

jquery.qrcode.min.js

(function( $ ){
    $.fn.qrcode = function(options) {
        // if options is string, 
        if( typeof options === 'string' ){
            options = { text: options };
        }

        // set default values
        // typeNumber < 1 for automatic calculation
        options = $.extend( {}, {
            render      : "canvas",
            width       : 256,
            height      : 256,
            typeNumber  : -1,
            correctLevel    : QRErrorCorrectLevel.H,
                        background      : "#ffffff",
                        foreground      : "#000000"
        }, options);

        var createCanvas    = function(){
            // create the qrcode itself
            var qrcode  = new QRCode(options.typeNumber, options.correctLevel);
            qrcode.addData(options.text);
            qrcode.make();

            // create canvas element
            var canvas  = document.createElement('canvas');
            canvas.width    = options.width;
            canvas.height   = options.height;
            var ctx     = canvas.getContext('2d');

            // compute tileW/tileH based on options.width/options.height
            var tileW   = options.width  / qrcode.getModuleCount();
            var tileH   = options.height / qrcode.getModuleCount();

            // draw in the canvas
            for( var row = 0; row < qrcode.getModuleCount(); row++ ){
                for( var col = 0; col < qrcode.getModuleCount(); col++ ){
                    ctx.fillStyle = qrcode.isDark(row, col) ? options.foreground : options.background;
                    var w = (Math.ceil((col+1)*tileW) - Math.floor(col*tileW));
                    var h = (Math.ceil((row+1)*tileW) - Math.floor(row*tileW));
                    ctx.fillRect(Math.round(col*tileW),Math.round(row*tileH), w, h);  
                }   
            }
            // return just built canvas
            return canvas;
        }

        // from Jon-Carlos Rivera (https://github.com/imbcmdth)
        var createTable = function(){
            // create the qrcode itself
            var qrcode  = new QRCode(options.typeNumber, options.correctLevel);
            qrcode.addData(options.text);
            qrcode.make();

            // create table element
            var $table	= $('<table></table>')
                .css("width", options.width+"px")
                .css("height", options.height+"px")
                .css("border", "0px")
                .css("border-collapse", "collapse")
                .css('background-color', options.background);

            // compute tileS percentage
            var tileW   = options.width / qrcode.getModuleCount();
            var tileH   = options.height / qrcode.getModuleCount();

            // draw in the table
            for(var row = 0; row < qrcode.getModuleCount(); row++ ){
                var $row = $('<tr></tr>').css('height', tileH+"px").appendTo($table);

                for(var col = 0; col < qrcode.getModuleCount(); col++ ){ $('<td></td>') .css('width', tileW+"px") .css('background-color', qrcode.isDark(row, col) ? options.foreground : options.background) .appendTo($row); } } // return just built canvas return $table; } return this.each(function(){ var element = options.render == "canvas" ? createCanvas() : createTable(); $(element).appendTo(this); }); }; })( jQuery );
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值