7

HTML代码

<img style="display: none" id="qrcode" data-width="100" data-height="100" data-url="https://www.baidu.com/">
/**
     * 生成二维码
     * data-width={宽度}
     * data-height={高度}
     * data-url={链接}
     * @param $ele
     */
   var generatorQRCODE = function ($ele) {
        $ele.hide();
        var params = $ele.data();
        if(!params['width'] || !params['height'] || !params['url']){
            console.log('生成二维码参数错误');
            return false;
        }
        var image = new Image();
        var imageUrl = "http://pan.baidu.com/share/qrcode?w=" + params['width'] + "&h=" + params['height'] + "&url=" + params['url'] + "";
        image.src = imageUrl;
        $ele.attr('src', imageUrl);
        $ele.show();
    };
    
    generatorQRCODE($("#qrcode"));

飞檐走壁的容MM
429 声望7 粉丝

+1