我正在使用条形码扫描仪,目前遇到一个问题,我需要条形码读取 2 个不同的值长度,目前我将其设置为以 9 长度提交值。
<span>
<input type="text" id="IC-input" name="IC" onkeyup="autofill(this.value)" placeholder="Enter your IC Number" required maxlength="12">
<label><button type="button" id="theButton" onclick="theButtonIsPressed()">Submit</button></label>
</span>
function autofill(value){
console.log("Autofill:"+value)
//console.log(9 digits);
button = document.getElementById("theButton");
if(value.length == 9){
console.log('form is ready to submit');
theButtonIsPressed(value);
}
}
现在我也需要它从 12 个值读取,但是当该值达到 9 位时它会自动提交。我试过 OR 功能。
function autofill(value){
console.log("Autofill:"+value)
//console.log(9 digits);
button = document.getElementById("theButton");
if(value.length == 12 || value.length == 9){
console.log('form is ready to submit');
theButtonIsPressed(value);
}
}
我也试过 Else 函数
function autofill(value){
console.log("Autofill:"+value)
//console.log(9 digits);
button = document.getElementById("theButton");
if(value.length == 12){
console.log('form is ready to submit');
theButtonIsPressed(value);
}
else if(value.length == 9){
theButtonIsPressed(value);
}
}
但它总是会读取前 9 个值,而不会读取其他 3 个值。有人对此有解决方案吗?先感谢您。
catspeake
森栏
30秒到达战场
相关分类