【发布时间】:2012-10-05 11:46:08
【问题描述】:
我从 Javascript 开始,我写了这个函数:
function disableField() {
if( document.getElementById("valorFinal").length > 0 ) ) {
document.getElementById("cantidadCopias").disabled = true;
}
}
如果第一个字段已填满,则会禁用名为 cantidadCopias 的第二个字段。
<label> <span>Valor final:</span>
<input type="text" class="input_text" name="valorFinal" id="valorFinal" onkeydown="disableField()"/>
</label>
<label> <span>Cantidad de Copias:</span>
<input type="text" class="input_text" name="cantidadCopias" id="cantidadCopias"/>
</label>
但是当第一个字段被填充时,它不会禁用第二个字段。
【问题讨论】:
-
有人拼写有问题 document.getElementById("valorFinal").lenght
-
您忘记告诉我们您的问题出在哪里。我们的问题是什么?
-
对不起,我已经编辑了问题。
-
你应该挂钩 onkeyup 而不是 onkeydown。此外,当第一个输入的长度再次达到 0 时,您应该再次启用第二个输入。以我的回答为例。
标签: javascript html disabled-input