我的表格中有三个文本框。如果数字文本框中的数字不等于0,我的目标是禁用验证和评估文本框。如何实现此目的?
伪码
if(digit.Text != 0 )
{
validate.enable = false;
evaluate.enable = false;
}
else
{
validate.enable = true;
evaluate.enable = true;
}
我的尝试
function disableME()
{
var numberTextBox = document.getElementById('number'),
validateTextBox = document.getElementById('validate'),
evaluateTextBox = document.getElementById('evaluate');
if (numberTextBox.value != 0)
{
validateTextBox.disable = true;
evaluateTextBox.disable = true;
}
else
{
validateTextBox.disable = false;
evaluateTextBox.disable = false;
}
}

<form action="welcome.php" method="post" id="myForm">
Number: <input type="number" id="number" onchange="disableME()"><br>
Validate: <input type="text" id="validate" onchange="disableME()"><br>
Evaluate: <input type="text" id="evaluate" onchange="disableME()"><br>
</form>
&#13;
答案 0 :(得分:2)
您应该使用ELEMENT.disabled
代替ELEMENT.disable
。
以下是对代码的更改:
function disableME()
{
var numberTextBox = document.getElementById('number'),
validateTextBox = document.getElementById('validate'),
evaluateTextBox = document.getElementById('evaluate');
if (numberTextBox.value != 0)
{
validateTextBox.disabled = true;
evaluateTextBox.disabled = true;
}
else
{
validateTextBox.disabled = false;
evaluateTextBox.disabled = false;
}
}
<form action="welcome.php" method="post" id="myForm">
Number: <input type="number" id="number" onchange="disableME()"><br>
Validate: <input type="text" id="validate" onchange="disableME()"><br>
Evaluate: <input type="text" id="evaluate" onchange="disableME()"><br>
</form>