html
<script src="https://cdn.staticfile.org/qrcodejs/1.0.0/qrcode.min.js"></script>
<script src="qrcode.min.js"></script>
<textarea type="text" placeholder="查找框" id="input1"></textarea>
<textarea type="text" placeholder="替换框" id="input2"></textarea>
<div id="qrcode"></div>
<button onclick="wifisc()">WIFI二维码生成</button>
JavaScript
function wifisc() {
var input1 = document.getElementById("input1").value;
var input = document.getElementById("input2").value;
var qrcodeDiv = document.getElementById("qrcode");
var content = `WIFI:S:${input1}\;T:WPA\;P:${input};H:true\;\;`;
if (input == null || input.length == 0) {
alert('请在“查找框”输入WIFI名称,“替换框”输入WIFI密码。');
}else if(input1 == null || input1.length == 0){
alert('请在“查找框”输入WIFI名称,“替换框”输入WIFI密码。');
} else {
var qrcode = new QRCode(qrcodeDiv, {
text: content,
width: 128,
height: 128
});
}};