我正在尝试使用JavaScript函数禁用和启用表单元素。选择某些组合框值时,将调用该函数。我的代码能够输入禁用和启用元素的函数,但元素永远不会改变状态。我已经在另一个测试页面上测试了我的代码,它运行成功。
以下是我的一些代码:
<script type="text/javascript">
function EnableMonsterFields(value)
{
if(value == "Monster Card")
{
document.getElementById("monsterCardType").disabled = false;
document.getElementById("level").disabled = false;
document.getElementById("monsterClassification").disabled = false;
document.getElementById("monsterAttribute").disabled = false;
document.getElementById("rank").disabled = false;
document.getElementById("qATK").disabled = false;
document.getElementById("qDEF").disabled = false;
document.getElementById("ATK").disabled = false;
document.getElementById("DEF").disabled = false;
}
}
function DisableMonsterFields(value)
{
if(value != "Monster Card")
{
document.getElementById("monsterCardType").disabled = true;
document.getElementById("level").disabled = true;
document.getElementById("monsterClassification").disabled = true;
document.getElementById("monsterAttribute").disabled = true;
document.getElementById("rank").disabled = true;
document.getElementById("qATK").disabled = true;
document.getElementById("qDEF").disabled = true;
document.getElementById("ATK").disabled = true;
document.getElementById("DEF").disabled = true;
}
}
</script>
我的onChange电话:
<tr>
<td>Card Type</td>
<td><select name="cardType" id ="cardType" onChange="EnableMonsterFields(this.value); DisableMonsterFields(this.value)">
<option selected value ="Choose One">Choose One</option>
<?php
while ($row = mysqli_fetch_array($resultSet))
{
echo ("<option value='" .$row['cardType'] ."'>" . $row['cardType'] . "</option>");
}
?>
</select>
</td>
</tr>
有什么想法吗?