温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

基于JS怎么实现二维码名片生成

发布时间:2022-06-23 13:49:29 来源:亿速云 阅读:205 作者:iii 栏目:开发技术

这篇文章主要介绍“基于JS怎么实现二维码名片生成”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“基于JS怎么实现二维码名片生成”文章能帮助大家解决问题。

演示

基于JS怎么实现二维码名片生成

基于JS怎么实现二维码名片生成

技术栈

这里用到了一个二维码生成库qrcode.js下面是简单介绍:

//初始化QRCode对象
var qrcode = new QRCode(document.getElementById("qrcode"));
//也可以在初始化QRCode对象,传入更多参数
var qrcode = new QRCode(document.getElementById("qrcode"),{
width: 128,
height: 128,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
//需要生成二维码的字符串
qrcode.makeCode("http://www.leixuesong.cn");
//清除二维码
qrcode.clear();
var qrcode = new QRCode("qrcode");

function makeCode () {      
    var elText = document.getElementById("text");
    
    if (!elText.value) {
        alert("Input a text");
        elText.focus();
        return;
    }
    
    qrcode.makeCode(elText.value);
}

makeCode();

$("#text").
on("blur", function () {
    makeCode();
}).
on("keydown", function (e) {
    if (e.keyCode == 13) {
        makeCode();
    }
});

源码

css

*{/* 通配符: 选择到所有的标签元素 */
				margin:0;/*外边距*/
				padding:0;/*内边距*/
			}
			body{/* 标签选择器 */
				background-image: linear-gradient(#1e045f, #032561, #183661);
				background-position:center top;/*背景定位:左右 上下*/
			}
			.content{
				width:950px;
				margin:auto;
			}
			#wrap{/* # id选择器*/
				float:left;
				width:480px;/* 宽度 */
				height:280px;/* 高度 */
				/*background:#933;*/
				margin:100px;

			}
			#wrap p{/*混合选择器*/
				float:left;
				width:200px;
				height:40px;
				border-radius:5px;/*圆角属性*/
				color:#fff;/*文字的颜色*/
				margin:20px 20px;
				overflow:hidden;/*超出隐藏*/
				text-align:center;
				line-height:40px;
			}
			#wrap p span{/*行内元素 : 设置宽高无效*/
				/*display:block;块元素占一行*/
				float:left;
				width:50px;
				height:40px;
				background:#333;
				/*text-align:center;文本左右居中*
				line-height:40px;/*行高*/
				
			}
			#wrap p input{
				float:left;
				width:150px;
				height:40px;
				border:0;
				background:#000;
				color:#fff;
				outline:none;/*轮廓*/
				text-indent:10px;/*首行缩进*/
			}
			#qrcode{
				float:left;/*左浮动:与父元素的左端对齐 依次的往右端显示*/
				width:260px;
				height:260px;
				border:1px solid red;/*边框线:宽度 类型(实心) 颜色*/
				margin-top:110px;/*上外边距100px*/
			}
			p#btn{/*选择器选择到越详细优先级越高*/
				width:450px;
				background:#6c0;
				cursor:pointer;/*鼠标手的形状*/
			}

js

var name='', company='',job='',adress='',moblie='',desc='';
			//特效思维:什么元素 触发 什么事件 实现 什么效果
			$("#btn").click(function(){//点击实现什么功能
				//alert("注意点,你点到我了")
				//获取值
				name = "FN:" + $("#name").val() + "\n";//获取值
				company = "ORG:" + $("#company").val() + "\n";
				job = "TITLE:" + $("#job").val() + "\n";
				adress = "WORK:" + $("#adress").val() + "\n";
				moblie = "TEL:" + $("#moblie").val() + "\n";
				desc = "NOTE:" + $("#desc").val() + "\n";
				var info ="BEGIN:VCARD\n" + name + company + job + adress + moblie + desc + "END:VCARD";
				//console.log(info);//在控制台输出
				//生成二维码
				var qrcode = new QRCode("qrcode");
				qrcode.makeCode(info);
			});

关于“基于JS怎么实现二维码名片生成”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

js
AI