llqrcode js識別二維碼解析二維碼信息實(shí)例
更新時(shí)間:2022年11月10日 10:36:33 作者:TANKING
這篇文章主要為大家介紹了llqrcode js識別二維碼解析二維碼信息實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
正文
llqrcode.js具有掃描二維碼功能,用來進(jìn)行從圖片中識別二維碼,可解析二維碼的信息。

代碼
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>llqrcode識別二維碼</title>
<script src="llqrcode.js"></script>
<script>
function getUrl(e,param){
analyticCode.getUrl(
param,e,function(url,param){
document.querySelector("#uploadQrcode").style.display = "none";
document.querySelector("#uploadQrcode_preview").innerHTML ="<img src='"+param+"' />";
document.querySelector("#qrcodeUrl").innerHTML ="識別內(nèi)容:"+ url;
document.querySelector("#rescan").style.display = "block";
}
)
}
let getObjectURL = function(file){
let url = null ;
if (window.createObjectURL!=undefined) {
url = window.createObjectURL(file) ;
} else if (window.URL!=undefined) {
url = window.URL.createObjectURL(file) ;
} else if (window.webkitURL!=undefined) {
url = window.webkitURL.createObjectURL(file) ;
}
return url ;
}
window.analyticCode = {
getUrl : function(type,elem,fn){
let url = null,src = null;
if(type === 'img-url'){
url = elem.src;
}else if(type === 'file-url' && elem.files.length > 0){
url = getObjectURL(elem.files[0]);
}
qrcode.decode(url);
qrcode.callback = function(imgMsg){
fn(imgMsg,url);
}
}
}
</script>
<style>
h3{
text-align: center;
margin-top: 100px;
}
#uploadQrcode{
width: 80px;
height: 80px;
margin:20px auto 0;
border: 2px dashed #ccc;
border-radius: 20px;
font-size: 25px;
line-height: 80px;
text-align: center;
color: #ccc;
position: relative;
cursor: pointer;
}
#selectQrcode{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
}
#qrcodeUrl{
text-align: center;
margin-top: 15px;
}
#uploadQrcode_preview{
width: 80px;
height: 80px;
margin:20px auto 0;
}
#uploadQrcode_preview img{
width: 80px;
height: 80px;
}
#rescan{
text-align: center;
text-decoration: none;
color: #666;
font-size: 15px;
margin-top: 15px;
display: none;
}
</style>
</head>
<body>
<h3>選擇一張二維碼圖片</h3>
<div id="uploadQrcode">
<span>+</span>
<input type="file" id="selectQrcode" onChange="getUrl(this,'file-url')" />
</div>
<!-- 圖片預(yù)覽 -->
<div id="uploadQrcode_preview"></div>
<!-- 識別結(jié)果 -->
<p id="qrcodeUrl"></p>
<a href="" id=" rel="external nofollow" rescan">重新識別</a>
</body>
</html>以上就是llqrcode js識別二維碼解析二維碼信息實(shí)例的詳細(xì)內(nèi)容,更多關(guān)于llqrcode js識別解析二維碼信息的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
JS從非數(shù)組對象轉(zhuǎn)數(shù)組的方法小結(jié)
這篇文章主要給大家介紹了關(guān)于JS從非數(shù)組對象轉(zhuǎn)數(shù)組的一些方法,分別是Array.prototype.slice.call(obj)、Array.from(obj)、[…obj]和Object.values(obj)等方法的詳細(xì)實(shí)現(xiàn)方法,需要的朋友可以參考下。2018-03-03
JavaScript中forEach和map方法的使用與區(qū)別
眾所周知map和forEach是數(shù)組的操作方法,下面這篇文章主要給大家介紹了關(guān)于JavaScript中forEach和map方法的使用與區(qū)別,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02
使用auto.js實(shí)現(xiàn)自動(dòng)化每日打卡功能
這篇文章主要介紹了使用auto.js實(shí)現(xiàn)自動(dòng)化每日打卡,本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-08-08
很不錯(cuò)的兩款Bootstrap Icon圖標(biāo)選擇組件
這篇文章主要介紹了不容錯(cuò)過的兩款Bootstrap Icon圖標(biāo)選擇組件,支持自定義的圖標(biāo),拿出來分享下,絕對的干貨,感興趣的小伙伴們可以參考一下2016-01-01
關(guān)于JavaScript中forEach和each用法淺析
這篇文章主要給大家介紹了關(guān)于JavaScript中forEach和each使用方法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編一起來學(xué)習(xí)學(xué)習(xí)吧。2017-07-07

