禁止输入字段,如果第二个输入字段填 [英] Disable an input field if second input field is filled

查看:178
本文介绍了禁止输入字段,如果第二个输入字段填的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于禁止输入字段,如果第二个输入字段填的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆