If语句,仅在数字不低于实际值时执行代码

If statement that will only to execute the code if the number is not lower than it is

本文关键字:执行 代码 不低于 语句 数字 If      更新时间:2023-09-26

我有一个整数,比方说9。我想创建一个条件,允许用户只在这个9不低于它的情况下点击按钮。我该如何处理呢?

if(not lower than 9){
  execute the code here....
}

假设您已经在名为num的变量和id为"Btn1"的按钮中获得了该整数的值,您可以尝试类似于以下代码:

if (num >= 9)
{
    $("#Btn1").removeAttr("disabled");
}
else
{
    $("#Btn1").attr("disabled", "disabled");
}

.removeAttr("disabled")将启用该按钮,.attr("disabled", "disabled")将禁用该按钮。

遗憾的是,

9永远是9。但是如果9被赋值给一个变量,那么你可以执行if (variable >= 9) { .... }

事实上,考虑到你的情况有多奇怪,它会按照你想要的方式工作

if (9) {
   // code
}

if (true) {相同,但这里,9不小于9,它等于9,因此它将进入条件。讨论。只是不要测试0