Input = "number" dan javascript uchun qiymatni oling

Men bu yerda va Internetda hamma narsani topdim va bu faqat ishlamaydi.

Ma'lumotlar bazasida mavjud raqamga mos keladimi-yo'qligini ko'rish uchun kirish turi = "raqam" ni tekshirishni istayman. Men hozirgi kunga qadar men oddiy narsani saqlab qoldim, chunki qolgan narsalarni ishlay olaman.

Mana mening kodim:

Kirish:

 <input style="width: 50px; font-size: 17px;" type="number" min="1" autocomplete="off" id="days" name="days" value="1" onchange="daysChange(this.days)" required />

Javascript bu erda:

 function daysChange(days) {
     var day = document.getElementById("days");
     if (day == "3"){
         alert("You Already Have An Email Going Out That Day. Please Select Another Day.");
     }
 }

It's not picking up the value of days. Instead if I do an alert and have it output the value this is what it says... [object HTMLInputElement]

0
day.value harakat qilib ko'ring. if (day.value == "3") {} .
qo'shib qo'ydi muallif kind user, manba
kun ichida HTML elementi mavjud. Ushbu elementdagi qiymatni olishingiz kerak. yuqorida aytib o'tilgan izohda aytib o'tilganidek
qo'shib qo'ydi muallif CaptainHere, manba

9 javoblar

Siz qiymat olishingiz kerak:

function daysChange(days) {
 var day = document.getElementById("days");
 if (day.value == "3"){
 alert("You Already Have An Email Going Out That Day. Please Select Another Day.");
 }
 }
2
qo'shib qo'ydi

Siz qiymat olishingiz kerak:

function daysChange(days) {
 var day = document.getElementById("days");
 if (day.value == "3"){
 alert("You Already Have An Email Going Out That Day. Please Select Another Day.");
 }
 }
2
qo'shib qo'ydi

Siz qiymat olishingiz kerak:

function daysChange(days) {
 var day = document.getElementById("days");
 if (day.value == "3"){
 alert("You Already Have An Email Going Out That Day. Please Select Another Day.");
 }
 }
2
qo'shib qo'ydi

Avval aytib o'tganimizdek, siz HTMLInput qiymatini olishingiz kerak:

if (day.value === "3")

Bundan tashqari, yaxshi nuqta, kirish qiymatining turi string hisoblanadi, men ishonaman, sizga tamsayı kerak, shuning uchun parseInt uchun stenografiya xususiyatidan foydalanib:

if (day.value|0 === 3)

Juda yoqimlimi?

0
qo'shib qo'ydi

Avval aytib o'tganimizdek, siz HTMLInput qiymatini olishingiz kerak:

if (day.value === "3")

Bundan tashqari, yaxshi nuqta, kirish qiymatining turi string hisoblanadi, men ishonaman, sizga tamsayı kerak, shuning uchun parseInt uchun stenografiya xususiyatidan foydalanib:

if (day.value|0 === 3)

Juda yoqimlimi?

0
qo'shib qo'ydi

Avval aytib o'tganimizdek, siz HTMLInput qiymatini olishingiz kerak:

if (day.value === "3")

Bundan tashqari, yaxshi nuqta, kirish qiymatining turi string hisoblanadi, men ishonaman, sizga tamsayı kerak, shuning uchun parseInt uchun stenografiya xususiyatidan foydalanib:

if (day.value|0 === 3)

Juda yoqimlimi?

0
qo'shib qo'ydi

Yuqorida aytib o'tilgan bolalar kabi, document.getElementById ("days") mos keladigan barcha ob'ektni qaytaradi. Joriy kirish qiymatini olish uchun value xususiyati kerak. Ishlaydigan misol:

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

function daysChange(days) {
  var day = document.getElementById("days");
  
  if (day.value == "3"){
     alert("You Already Have An Email Going Out That Day. Please Select Another Day.");
  }
}
<input style="width: 50px; font-size: 17px;" type="number" min="1" autocomplete="off" id="days" name="days" value="1" onchange="daysChange(this.days)" required />
</div> </div>
0
qo'shib qo'ydi

Yuqorida aytib o'tilgan bolalar kabi, document.getElementById ("days") mos keladigan barcha ob'ektni qaytaradi. Joriy kirish qiymatini olish uchun value xususiyati kerak. Ishlaydigan misol:

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

function daysChange(days) {
  var day = document.getElementById("days");
  
  if (day.value == "3"){
     alert("You Already Have An Email Going Out That Day. Please Select Another Day.");
  }
}
<input style="width: 50px; font-size: 17px;" type="number" min="1" autocomplete="off" id="days" name="days" value="1" onchange="daysChange(this.days)" required />
</div> </div>
0
qo'shib qo'ydi

Yuqorida aytib o'tilgan bolalar kabi, document.getElementById ("days") mos keladigan barcha ob'ektni qaytaradi. Joriy kirish qiymatini olish uchun value xususiyati kerak. Ishlaydigan misol:

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

function daysChange(days) {
  var day = document.getElementById("days");
  
  if (day.value == "3"){
     alert("You Already Have An Email Going Out That Day. Please Select Another Day.");
  }
}
<input style="width: 50px; font-size: 17px;" type="number" min="1" autocomplete="off" id="days" name="days" value="1" onchange="daysChange(this.days)" required />
</div> </div>
0
qo'shib qo'ydi
Javascript UZB
Javascript UZB
99 ishtirokchilar

@js_uzb @vuejs_uz @react_uz @nodejs_uz @angular_uz @ngTashkent @yiiframework_uz @laravel_uz @linux_uzbek @python_uz @swift_uzb —————— @uzdevgroup @UzGeeksGroup ——— @UzDev_Jobs @jobs_uzb