如果javascript中文本输入中的条件为true,则停用复选框
Deactivate checkbox if a condition in a text input is true in javascript
我有几个文本输入和一个复选框数组。如果文本输入的值小于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>
如果你不理解上面的程序,可以问任何问题。
使ID唯一。以下是我尝试过的
<script>
function desactivacasillas() {
var formularioprincipal = document.getElementById("troncocomun");
var primerelemento = document.getElementById("1").value;
if (document.getElementById("1").value < 6) {
var checkbox1 = document.getElementById("checkbox2");
checkbox1.disabled = true;
}
}
</script>
<table>
<tr>
<td nowrap id="materia">ALGEBRA</td>
<td>5.62</td>
<td>
<input type="text" id="1" name="1" value="6" 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="checkbox2" value="5.62">
</td>
</tr>
</table>
试试这个。使用java脚本中的on-load函数可以在加载时禁用复选框。并使用parse Int函数,因为输入以字符串形式返回值。
更改复选框的ID。ID总是唯一的。
<script>
function disableCheckbox(){
document.getElementById("checkbox2").disabled = true;
}
function desactivacasillas() {
var formularioprincipal = document.getElementById("troncocomun");
var primerelemento = document.getElementById("1").value;
if (parseInt(document.getElementById("1").value,10) > 6) {
document.getElementById("checkbox2").disabled = false;
}
}
</script>
<body onload="disableCheckbox();">
<table>
<tr>
<td nowrap id="materia">ALGEBRA</td>
<td>5.62</td>
<td>
<input type="text" id="1" name="1" onkeyup="desactivacasillas(event)">
</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>
相关文章:
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- JavaScript-切换“;全部检查”;复选框true/false
- 根据签入的表单,在html电子邮件模板中将复选框标记为true
- 如何通过javarscript或jquery在数组中添加属性复选框(checked=true)
- HTML 复选框 Click() 使用 jQuery 返回 FALSE 或 TRUE,而不是 READONLY 或 DI
- 输入复选框 true 或选中或是
- Angularjs 设置复选框为 true
- JQuery 复选框不会更改 .prop(“checked”, true) 处的视觉状态
- 用于更改true与false函数值的复选框
- checked=true,来自前面的复选框
- 当取消选中jQuery时,复选框仍然显示为true
- 将复选框的默认值绑定到角度模型,其中true和amp;false表示为'是'&'没有'
- 使用jQuery将使用复选框的数据属性从false更改为true
- 根据Webix中的复选框值编辑true/false
- 如果第一个的返回值为true,则显示第二个复选框
- 在ng-click中,复选框返回false而不是true
- Javascript复选框在移动设备上总是返回true
- AngularJS复选框动态ng-true-value表达式
- ASP.复选框上的灰色字段= true
- 当javascript中checked属性设置为true时,复选框在UI中不会显示为checked