我正在尝试使用Google Chart API创建QR代码。
尝试用这件代码玩具玩具,但是有些无法使其无法正常工作。并不是真正的专家。因此,任何帮助都会很棒。谢谢
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="https://net-raft.com/plugins/jquery/toggle_input/ToggleInput.js" type="text/javascript">
</script>
</head>
<body>
<input id="myID" type="text" value="mypassword"></br>
<button type="button">click</button>
<script>
$(document).ready(function () {
$("button").click(function () {
var myattr = $("#myID").attr("type");
$("#myID").Toggle_Input(myattr);
});
});
$(document).ready(function (){
var url = $(location).attr('href');
$("div").html("<img src='https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=" + url + "&choe=UTF-8' alt='QR code' />n");
});
</script>
</body>
</html>
您忘了添加QR代码占位符:<div id="div"></div>
。下一个问题是Google Chart API QR生成器已弃用,您可以使用自己在PHP中实现的生成器或使用一些可靠的在线服务,请参阅此讨论
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="https://net-raft.com/plugins/jquery/toggle_input/ToggleInput.js" type="text/javascript">
</script>
</head>
<body>
<div id="div"></div>
<input id="myID" type="text" value="mypassword"></br>
<button type="button">click</button>
<script>
$(document).ready(function () {
$("button").click(function () {
var myattr = $("#myID").attr("type");
$("#myID").Toggle_Input(myattr);
});
});
$(document).ready(function (){
var url = $(location).attr('href');
$("div").html("<img src='https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=" + url + "&choe=UTF-8' alt='QR code' />n");
});
</script>
</body>
</html>