好吧,所以我有一个需要禁用的按钮。我编写了一个JavaScript函数,用于检测字段是否为空/空,以及是否禁用字段旁边的保存按钮。它似乎正在检测空白字段并抛出警报,但无论我尝试什么,只要将按钮设置为禁用即可。我无法做到这一点。为什么不能禁用按钮工作
以下是我目前正在尝试...
function validateBlank(){
var x = document.forms["FuForm"]["Field1"].value;
if (x=null || x == "") {
alert("Must Be Between 1 and 300 Characters");
document.getElementById("saveTest").setAttribute("disabled", "disabled");
return false;
}
}
我也试过这种变异......
document.getElementById("saveTest").disabled
和按钮/链接为建立这样的。
<a href="#">
<img id="saveButton" src="${contextPath}/img/icon_sav.gif" name="saveTest" " alt="Disk icon. Save change" title="Save change"/>
</a>
这不是一个按钮,它是一个图像。你不能禁用图像 –
它既不是 - saveTest不是任何*的id。不过,saveButton是图像的id。 –
另一个错字:'if(x = null)...'应该是'if(x == null)...' –