Tự nhiên hôm nay mò lại mấy web xtgem lại thấy cái code hay ho này. Đoạn code javascript giúp bạn có một trang web tạo QR code online. Code công cụ tạo mã QR đơn giản nhất.
Demo: http://qrqr.xtgem.com
BƯỚC 1:
- Tạo thư mục qrcode
- Upload 3 file js này lên thư mục vừa tạo:
http://qrqr.xtgem.com/jquery.min.js
http://qrqr.xtgem.com/qrcode.js
http://qrqr.xtgem.com/qrcode.min.js
BƯỚC 2: Dán code sau vào nơi muốn hiển thị công cụ tạo QR:
Code:
<script type="text/javascript" src="qrcode/jquery.min.js"></script>
<script type="text/javascript" src="qrcode/qrcode.js"></script>
<script type="text/javascript" src="qrcode/qrcode.min.js"></script>
<textarea id="text" style="width: 300px; height: 200px;">Nhập nội dung</textarea>
<div class="phdr">Kết quả</div>
<div id="qrcode" style="width:200px; height:200px; margin-top:15px;"></div>
<script type="text/javascript">
var qrcode = new QRCode(document.getElementById("qrcode"), {
width : 200,
height : 200
});
function makeCode () {
var elText = document.getElementById("text");
if (!elText.value) {
alert("Input a text (Hãy nhập nội dung)");
elText.focus();
return;
}
qrcode.makeCode(elText.value);
}
makeCode();
$("#text").
on("blur", function () {
makeCode();
}).
on("keydown", function (e) {
if (e.keyCode == 13) {
makeCode();
}
});
</script>
Hiện tại cái code này mình đang viết là nhập văn bản vào xong nhấn enter là QR sẽ được tạo. Anh em nào muốn đẹp hơn thì có thể làm thêm cái nút Submit nhé. Cái này đơn giản mà phải không.
Tạo bởi Fizz - ChemGio.Net