[英]Compare two values from Array
我正在尋找比較兩個輸入字段的輸入。 在創建兩個數組之前,因此,當數組“ lenghtOfBoat”的索引等於或大於數組“ HKboat”的索引時,它應該輸出一個文本字符串,說明特定內容。
這是我當前的代碼:(我還是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");
}
謝謝!
像這樣嗎? 我不知道它是否有效,但也許有幫助。
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.