我目前正在处理一个项目,我接管了从条形码读取的输入,目前我在输出方面遇到了麻烦,给了我一个固定值,代码可以从实际输入中读取,而不能从实际输入中读取。 > 下面的
是扫描仪的html代码。看起来很好
<div class="section" id="instruction-3">
<p>Otherwise, scan your code at the bottom, or manually type it in here:</p>
<span>
<input type="text" id="IC-input" name="IC" onclick="openKeyboard()" onkeyup="autofill(this.value)" placeholder="Enter your IC Number" required maxlength="9">
<label><button type="button" id="theButton" onclick="theButtonIsPressed()">Submit</button></label>
</span>
</div>
关注javascript(我怀疑这是问题所在,但不确定)
<script>
var NRIC = '{"NRIC":"0"}';
function theButtonIsPressed(){
closeKeyboard();
console.log('button clicked');
NRIC = '{"NRIC":"123456789"}';
//var IcNum = document.getElementById("IC-input").value;
//NRIC = NRIC.replace("0", IcNum);
document.getElementById("IC-input").value = "";
doWork(NRIC)
}
</script>
function doWork(NRIC) {
// ajax the JSON to the server
$.post("receiver", NRIC, function(){
});
// stop link reloading the page
function update() {
setInterval(function(){$.post("receiver", '{"NRIC":NRIC}', function(){});}, 900);
它一直在给我NRIC ='{“ NRIC”:“ 123456789”}';内部的值;是123456789,我意识到这可能是一个简单的解决方法,但我仍在学习并且不确定。
先谢谢您
答案 0 :(得分:1)
如果我正确理解您想在obj中输入输入值,请尝试以下操作:
function theButtonIsPressed(){
closeKeyboard();
console.log('button clicked');
var IcNum = document.getElementById("IC-input").value;
NRIC.NRIC = IcNum;
doWork(NRIC)
}
答案 1 :(得分:0)
为什么在object周围加引号?
var NRIC = {"NRIC": 0};
function theButtonIsPressed() {
NRIC = {"NRIC": 123456789};
doWork(NRIC)
}
答案 2 :(得分:0)
所有问题都解决了,但我的错是我没有提到我想将数据传输到另一个网页,这是我的错,原因是数据没有被传输到另一个html。
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);
}
}
function theButtonIsPressed(value){
closeKeyboard();
console.log('button clicked');
//NRIC = '{"NRIC":"123456789"}';
console.log(value)
doWork(value)
}
通过这样做,它从输入中读取了相应的值,然后进行了处理,再次抱歉我的困惑问题,并感谢所有尝试提供帮助的人。