$('#lithird').click(function(){var qrcode = new QRCode("qrcode");函数makeCode(){函数randomNumber(len){var randomNumber;var n ='';for(var count = 0; count #qrcode {宽度:160像素;高度:160像素;margin-top:15px;} <脚本src ="https://code.jquery.com/jquery-1.12.3.min.js"><;/script>< script src ="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script>< script src ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"</script>< link href ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel ="stylesheet"/>< div class ="container-fluid" id ="main">< ul class ="nav nav-tabs" role ="tablist">< li role ="presentation" id ="lifirst" class ="active">< a href =#home" aria-controls ="home" role ="tab" data-toggle ="tab">List</a>/li>< li role ="presentation" id ="lithird">< a href =#editable" aria-controls ="editable" role ="tab" data-toggle ="tab" onclick ='transfer_new()'>添加新</a</li></ul><!-/导航标签/-><!-标签窗格->< div class ="tab-content">< div role ="tabpanel" class ="tab-pane active" id ="home" style ="margin-top:10px;">在下一个塔巴AR代码中</div>< div role ="tabpanel" class ="tab-pane" id ="editable">< div class ="col-xs-12 col-sm-12 col-md-4 col-lg-4 col-md-offset-4 col-lg-offset-4">< div id ="qrcode"></div></div> =</div></div></div> 解决方案尝试添加 $('#qrcode').html(''); 作为中的第一项.click(function(){} 赞: $('#lithird').click(function(){$('#qrcode').html('');//< ---添加此内容,下次单击时应将其清除var qrcode = new QRCode("qrcode");函数makeCode(){函数randomNumber(len){var randomNumber;var n ='';for(var count = 0; count Codepen进行全面审核 I am using qrcode.js for generating qrcode. I want to generate random QR code every time I click into add new tab instead of add new qr code. I created a code for a random number but when I try to add onclick function it add new not to random it.JSFIDDLE: https://jsfiddle.net/aice09/L8pp9336/GITHUB: https://github.com/Ailyn09/project102/blob/master/qrcode.htmlCODEPEN: https://codepen.io/aice09/pen/Ogqajr$('#lithird').click(function() { var qrcode = new QRCode("qrcode"); function makeCode() { function randomNumber(len) { var randomNumber; var n = ''; for (var count = 0; count < len; count++) { randomNumber = Math.floor(Math.random() * 10); n += randomNumber.toString(); } return n; } var value = randomNumber(13); var elText = value; qrcode.makeCode(elText); } makeCode();});#qrcode { width:160px; height:160px; margin-top:15px;}<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script><script src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script><link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /><div class="container-fluid" id="main"> <ul class="nav nav-tabs" role="tablist"> <li role="presentation" id="lifirst" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">List</a></li> <li role="presentation" id="lithird"><a href="#editable" aria-controls="editable" role="tab" data-toggle="tab" onclick='transfer_new()'>Add New</a></li> </ul> <!--/ Nav tabs /--> <!-- Tab panes --> <div class="tab-content"> <div role="tabpanel" class="tab-pane active" id="home" style="margin-top: 10px;"> IN THE NEXT TABA THE AR CODE </div> <div role="tabpanel" class="tab-pane" id="editable"> <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 col-md-offset-4 col-lg-offset-4"> <div id="qrcode"></div> </div>= </div> </div></div> 解决方案 Try adding $('#qrcode').html(''); as the first item in the .click(function(){}Like this:$('#lithird').click(function(){ $('#qrcode').html(''); // <---Add this, which should clear it out on the next click var qrcode = new QRCode("qrcode"); function makeCode () { function randomNumber(len) { var randomNumber; var n = ''; for(var count = 0; count < len; count++) { randomNumber = Math.floor(Math.random() * 10); n += randomNumber.toString(); } return n; } var value = randomNumber(13); var elText = value; qrcode.makeCode(elText); } makeCode();});Codepen for full review 这篇关于使用qrcode.js生成随机QR码OnClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-07 17:06