我有几个文本输入和一个复选框数组。 如果文本输入的值小于 6,则禁用该复选框。 我尝试过此操作,但该复选框始终处于启用状态。
<script>
function desactivacasillas() {
var formularioprincipal = document.getElementById("troncocomun");
var primerelemento = document.getElementById("1").value;
if (document.getElementById("1").value < 6) {
var checkbox1 = document.getElementById("checkbox1").disabled = true;
}
}
</script>
<table>
<tr>
<td nowrap id="materia">ALGEBRA</td>
<td>5.62</td>
<td>
<input type="text" id="1" name="1" onkeydown="return validarnumero(event)" onkeypress="return compruebacampo(event,this)" onkeyup="desactivacasillas(event)">
</td>
<td>
<input type="hidden" name="carga[0]" id="checkbox1" value="0">
<input type="checkbox" name="carga[0]" id="checkbox1" value="5.62">
</td>
</tr>
</table>
你能告诉我我做错了什么吗?
最佳答案
试试这个
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
<script>
function desactivacasillas(args) {
if (document.getElementById("1").value.length < 6) {
$("#checkbox2").attr("disabled", true);
}
else
{
$("#checkbox2").attr("disabled", false);
}
}
</script>
<table>
<tr>
<td nowrap id="materia">ALGEBRA</td>
<td>5.62</td>
<td>
<input type="text" id="1" name="1" onkeyup="desactivacasillas(this.value)">
</td>
<td>
<input type="hidden" name="carga[0]" id="checkbox1" value="0">
<input type="checkbox" name="carga[0]" id="checkbox2" value="5.62">
</td>
</tr>
</table>
</body>
</html>
如果您不明白上述程序,请随时询问。
关于javascript - 如果文本输入中的条件在 javascript 中为 true,则停用复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23166756/