例如,我想用相同的信息生成10个不同的二维码。目前,我每次只能生成一个二维码。我应该放入一个循环还是任何解决方案?
function makeCode () {
// All inputs that contain the value
$qrs = $('.qr_value');
// Create a new instance of the QRCode for each input
$qrs.each(function(index, item){
// We cant hace same id multiple times, so, we need to create dynamic ids,
// thats why we are concatenating the index to the id string
let containerQr = "qrcode_"+index;
// Create QR
let qrcode = new QRCode(containerQr, {
text: item.value, // value to read on qr
width: 500,
height: 500,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H,
});
});
}
makeCode();// loop on any technology that u use, is php on my case
foreach($values as $key => $value){
<input type="hidden" class="qr_value" value="$value">
<div id="qrcode_$key"></div>
}
发布于 2020-06-03 12:43:18
使用一个简单的for()循环,并在生成二维码的代码周围迭代一个计数器。
let i = 1;
while( i <= 10){
qrcode.clear(); // clear the code.
qrcode.makeCode(); // make another code.
}
for(let i = 1; i <= 10; i++){
// generate your qr code
console.log(i)
}
https://stackoverflow.com/questions/62165203
复制相似问题