将按钮绑定到几个基于文本框中值的大小而激活的文本框

Binding Buttons to several text boxes actived based on size of values in text box

本文关键字:文本 激活 于文本 绑定 按钮 几个      更新时间:2023-09-26

我正在建立一个网站,人们可以在订购产品之前自定义产品的形状。

最终将有几个按钮绑定到四个文本框中。当用户在文本框中输入更高的值时,激活的按钮会发生变化,因此我们知道需要为该客户的设计订购什么尺寸的材料片。

如何根据文本框中的值创建启用/禁用的按钮?

您可以使用jQuery并尝试以下操作:

首先,给你的按钮一个属性disabled="disabled",然后:

//Assuming they are typing, if it's a dropdown/select, see below
$('#input-id').on('keyup', function() {
    if($(this).val() >= 10 && $(this).val() <= 20) { // If the value is between 10 and 20...
      $('#button-id').removeAttr('disabled'); // Remove disabled attribute
    } else { // If the value is not our keyword...
      if(!$('#button-id').attr('disabled')) { // And the button is not disabled...
        $('#button-id').attr('disabled', 'disabled'); // Readd disabled attribute
      }
    }
});

如果使用下拉框或选择框,请使用$("select option:selected")