网上找到个非常简便的代码:
<input type="text" id="sn">
<a href="https://www.996315.com/api/scan/?redirect_uri=http://192.168.3.49:5500/tt/query.html">扫描(Scan)</a>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
var qr=GetQueryString("qrresult");
if(qr){
$("#sn").val(qr);
}
function GetQueryString(name){
var reg = new RegExp("\\b" + name + "=([^&]*)");
var r = location.href.match(reg);
if (r!=null) return decodeURIComponent(r[1]);
}
</script>
注意把redirect_uri=后面的网址改成你本地当前的url
不知道ip地址是否能自动回调,有时间试试:
<input type="text" id="sn">
<a href="https://www.996315.com/api/scan/">扫描(Scan)</a>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
var qr=GetQueryString("qrresult");
if(qr){
$("#sn").val(qr);
}
function GetQueryString(name){
var reg = new RegExp("\\b" + name + "=([^&]*)");
var r = location.href.match(reg);
if (r!=null) return decodeURIComponent(r[1]);
}
</script>