h5 generate QR codes online via jquery and QRCode
First we need to download a qrcode.js file and then introduce jquery and QRCode files in turn.
1. Create an input box for demonstration use:
<id= "text" type= "text" value= "http// Www.baidu.com " style=" width:80%"/>
2. Create a div to place the two-dimensional code image (the div ID is defined as "QRCode"):
<id= "QRCode" style= "width:100px; height:100px; margin-top:15px;" ></ Div >
3. Insert JS Code:
1 varQRCode =NewQRCode (document.getElementById ("QRCode"), {2width:100,3height:1004 });5 6 functionMakecode () {7 varEltext = document.getElementById ("text");8 9 if(!eltext.value) {TenAlert ("Input a text"); One Eltext.focus (); A return; - } - the Qrcode.makecode (eltext.value); - } - - Makecode (); + -$ ("#text"). +On ("Blur",function () { A Makecode (); at }). -On ("KeyDown",function(e) { - if(E.keycode = = 13) { - Makecode (); - } - }); in</script
This allows you to generate two-dimensional code online!
Is our code, try to scan under the phone will not jump to Baidu home page.
H5 development app to generate two-dimensional code online