JS生成二维码(兼容各种浏览器及中文)
2017-07-11 16:49
302 查看
本文将介绍如何使用js生成二维码,兼容各种浏览器及手机端,支持中文。 <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title> JS 生成二维码 </title> <script src="qrcode.js"></script> <script type="text/javascript"> window.onload = function(){ // 二维码对象 var qrcode; // 默认设置 var content; var size; // 设置点击事件 document.getElementById("send").onclick =function(){ // 获取内容 content = document.getElementById("content").value; content = content.replace(/(^\s*)|(\s*$)/g, ""); // 获取尺寸 size = document.getElementById("size").value; // 检查内容 if(content==''){ alert('请输入内容!'); return false; } // 检查尺寸 if(!/^[0-9]*[1-9][0-9]*$/.test(size)){ alert('请输入正整数'); return false; } if(size<100 || size>500){ alert('尺寸范围在100~500'); return false; } // 清除上一次的二维码 if(qrcode){ qrcode.clear(); } // 创建二维码 qrcode = new QRCode(document.getElementById("qrcode"), { width : size,//设置宽高 height : size }); qrcode.makeCode(document.getElementById("content").value); }}</script> </head> <body>< be82 span class="token p" style="color:rgb(90,90,90);font-size:18px;white-space:pre-wrap;"> <p>内容:<input type="text" id="content" value="https://www.baidu.com" /></p> <p>尺寸:<input type="text" id="size" value="150"></p> <p><button id="send">生成二维码</button></p> <div id="qrcode"></div> </body> </html> 请自行下载qrcode.js文件
相关文章推荐
- JS生成二维码(兼容各种浏览器及中文)
- 万能js实现翻页,动态生成内容自动翻页,兼容各种浏览器(已测试)----神器版!
- 万能js实现翻页,动态生成内容自动翻页,兼容各种浏览器(已测试)----神器版!
- JS生成二维码,支持中文字符
- (造福中国前端界)纯前端Js完美解决各种汉字urlencode,urldecode,编码解码问题,不借助任何字库,内码表,轻松一行,兼容IE8+,chrome,firefox,safari等主流浏览器
- 使用Jquery.QRCode.js在web客户端生成二维码包括中文
- 前台JS(type=‘file’)读取本地文件的内容,兼容各种浏览器 二
- js动态生成DIV(根据鼠标点击处生成DIV,兼容浏览器)
- js 获取屏幕各种宽高的方法(浏览器兼容)
- js,jquery字符串转换json,兼容各种浏览器
- JS生成二维码,支持中文字符
- 基于asp.net + easyui框架,js实现上传图片之前判断图片格式,同时实现预览,兼容各种浏览器+下载
- 前台JS(type=‘file’)读取本地文件的内容,兼容各种浏览器 一
- js操作iframe兼容各种浏览器
- 使用jquery-qrcode生成二维码(兼容中文)
- js,jquery字符串转换json,兼容各种浏览器
- 纯js实现Div在页面垂直居中!可根据浏览器大小的改变而改变!兼容各种浏览器----神器版!
- 精品js Firefox 加入收藏夹功能代码 兼容Firefox 和 IE等各种浏览器
- js 实现文字无缝滚动(图片无缝滚动) 兼容各种浏览器
- 调用iframe 中的js[兼容各种浏览器]