我正在处理一个网页列表,该列表在单击时会产生QR码。 QR码根据选择的选项而变化。现在,我们有一个HTML下拉列表,此JS从文本文件读取以自动更新列表并生成QR。我正在尝试将其转换为仅从html中的
function updateList(text)
{
var arr = text.split("\n")
for(var i in arr) {
var option = document.createElement("option");
var content = arr[i].split("*")
option.text = content[0];
console.log(option.text);
option.value = content[1];
console.log(option.value);
var select = document.getElementById("myList");
select.appendChild(option);
}
}
function setPicture()
{
var dv = document.getElementById('qrcode');
// clear previous qr code
while (dv.hasChildNodes()) {
dv.removeChild(dv.lastChild);
}
var list = document.getElementById('myList');
//point to url and pass to qrGen function
var link = list.options[list.selectedIndex].value;
console.log(link);
qrGen(link);
}
function openText(file)
{
var allText = '';
$("div").append("<option></option>");
var buffer = new XMLHttpRequest();
buffer.open("GET",file,false);
buffer.onreadystatechange = function ()
{
if(buffer.status == 200 && buffer.readyState == 4){
allText = buffer.responseText;
}
}
buffer.send(null);
updateList(allText)
}
function qrGen(link)
{
{
new QRCode(document.getElementById("qrcode"),link);
}
}
</script>