禁止输入字段,如果第二个输入字段填字段、第二个

2023-09-10 19:10:06 作者:付词与菊i

完全是一个新手... 我只是想知道如何动态禁用输入字段时,第二个输入字段填

totally a newbie... I just want to know how to dynamically disable an input field when the second input field is filled

例如:

<td><input type="text" name="num-input1" id="dis_rm"  value=""></input></td>
<td><input type="text" name="num-input2" id="dis_per" value="" ></input></td>

请...任何联系,并暗示将尽...

pls... any links and hints will do...

推荐答案

您只需给它一个disabled属性:

You simply need to give it a disabled property:

document.getElementById("dis_rm").disabled = true;
document.getElementById("dis_per").disabled = true;

您可以使用上的变化事件,看看是否其中一人是充满:

you can use the on change event to see if one of them is filled:

var dis1 = document.getElementById("dis_rm");
dis1.onchange = function () {
   if (this.value != "" || this.value.length > 0) {
      document.getElementById("dis_per").disabled = true;
   }
}

因此​​,如果第一个被填满后,第二个将被禁用。

so if the first one is filled, the second one will be disabled