zoukankan      html  css  js  c++  java
  • 常用分享功能.超级简单,qq 微信 新浪微博分享

    <div id="share">
                <a href="javascript:void(0)"  share-type="qzone"  style="background-position: 0 0;"     target="_blank"  title="分享到QQ空间"></a>
                <a href="javascript:void(0)"  share-type="tsina"  style="background-position: -35px 0;" target="_blank"  title="分享到新浪微博"></a>
                <a href="javascript:void(0)"  share-type="weixin" style="background-position: -70px 0;" target="_blank"  title="分享到微信朋友圈"><div class="erweima"><div id="qrcode"></div></div></a>
            </div>
    

    这是html;

    下边是JS

    $(function () {
    
        var qrcode = new QRCode(document.getElementById("qrcode"), {
            width : 160,//设置宽高
            height : 160
        });
        qrcode.makeCode(location.href);
        
        $('#share a').on('click',share);
    
    
        var shareDara = {
            pic:(function () {
                var pics = ''
                $('.contenr-main .text img').each(function (i,k) {
                    if(i<1){
                        pics +=  $(k).attr('src')
                    }else{
                        pics += '||'+$(k).attr('src')
                    }
                })
                return pics
            })(),
            title:(function () {
               return $('.contenr-main .title').html()
            })(),
            url:location.href,
            desc:(function () {
                return $('.contenr-main .text p').eq(0).html()
            })()
        }
    
    
    
        function share (){
            var self = $(this);
            var shareType = self.attr('share-type');
                //console.log(shareType);
            switch (shareType){
                case 'weixin':
                    break;
                case 'tsina':
                    self.attr('href',
                        'http://service.weibo.com/share/share.php?' +
                        'url=' +encodeURIComponent(shareDara.url)+
                        '&title=' +encodeURIComponent(shareDara.title)+
                        '&appkey=93034926' +
                        '&pic='+encodeURIComponent(shareDara.pic)+
                        '&searchPic=false')
                    break;
                case 'qzone':
                    self.attr('href',
                        'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?' +
                        'url='  +encodeURIComponent(shareDara.url)+
                        '&title=' +encodeURIComponent(shareDara.title)+
                        '&desc=' + encodeURIComponent(shareDara.desc)+
                        '&summary=' +encodeURIComponent(shareDara.pic)+
                        '&site='
                        )
                    break;
                default:
                    break;
    
            }
        }
    
    });
    

      再从网上下载一个qrcode.min.js用来生成二维码超级简单实用

    不自见,故明;不自是,故彰;不自伐,故有功;不自矜;故长;夫唯不争,故天下莫能与之争。
  • 相关阅读:
    datagrid
    SQL语句
    JavaScript事件
    DOM和BOM
    JavaScript基础知识
    css
    网络编程常识
    集合框架
    多线程常识
    面向对象常识
  • 原文地址:https://www.cnblogs.com/chengfeng6/p/6694117.html
Copyright © 2011-2022 走看看