简体   繁体   English

比较数组中的两个值

[英]Compare two values from Array

I'm looking to compare the input of two input fields. 我正在寻找比较两个输入字段的输入。 Before that two Arrays have been created, so when the index of the array 'lenghtOfBoat' is equal or higher than the index of the array 'HKboat', it should output a text string saying something specific. 在创建两个数组之前,因此,当数组“ lenghtOfBoat”的索引等于或大于数组“ HKboat”的索引时,它应该输出一个文本字符串,说明特定内容。

This is my current code: (I'm still new to JS, but trying my best) 这是我当前的代码:(我还是JS的新手,但是我会尽力而为)

var lenghtOfBoat = [4, 5, 6, 7, 8, 9];
var inputBoatLenght = document.getElementById("boatLenght");

var statusLength = inputBoatLenght.addEventListener("change", function() {
  if(lenghtOfBoat.indexOf(+this.value) > -1){
    console.log(this.value);
  }else{
    console.log(this.value);
  }
  return this.value
})


var HKboat = [4.10, 5.15, 6, 7, 8, 9];
var inputBoatHK = document.getElementById("boatHK");

var statusHK = inputBoatHK.addEventListener("change", function() {
  if(HKboat.indexOf(+this.value) > -1){
    console.log(this.value);
  }else{
    console.log(this.value);
  }
  return this.value
})


if(statusLength <= statusHK) {
    console.log("Yipsi");
}

Thanks! 谢谢!

And something like this? 像这样吗? I don't know if it works but maybe it helps. 我不知道它是否有效,但也许有帮助。

var lenghtOfBoat = [4, 5, 6, 7, 8, 9];
var inputBoatLenght = document.getElementById("boatLenght");

inputBoatLenght.addEventListener("change", function() {
  //Gather info and send check
  checkValues(this.value, inputBoatHK.value);
})


var HKboat = [4.10, 5.15, 6, 7, 8, 9];
var inputBoatHK = document.getElementById("boatHK");

inputBoatHK.addEventListener("change", function() {
  //Gather info and send check
  checkValues(inputBoatLenght.value, this.value);
})

function checkValues (statusLength, statusHK) {
  if(statusLength <= statusHK) {
    console.log("Yipsi");
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM