正如标题所说,我正在尝试在打开文件时禁用文本框
<form name='registration' action="registration.php" method="post" onSubmit="return formValidation();">
<table>
<tr>
<td>FirstName:</td>
<td><input type = "Text" name = "firstname" id="1"></p></td>
</tr>
</table>
</form>
我尝试使用以下 javascript 代码禁用它:
function formValidation() {
var fn = document.registration.firstname;
if(fname_validation(fn)) {}
document.getElementById("1").disabled = true;
}
function fname_validation(fn) {
var fn_len = fn.value.length;
var fn_char = /^[A-Za-z]+$/;
if (fn_len == 0) {
alert("first name cannot empty");
return false;
}
if (!fn.value.match(fn_char)) {
alert("first name must enter alphabet only");
return false;
} else {
return true;
}
}
为什么文本框仍然没有禁用?