如何使用AJAX启用和禁用按钮获取错误admin.php:15未捕获的ReferenceError:$未定义
function validate() {
// Find the validation image div
var validationElement = document.getElementById('nameValidation');
// Get the form values
var password1 = document.forms["Admin"]["password1"].value;
var password2 = document.forms["Admin"]["password2"].value;
// Reset the validation element styles
validationElement.style.display = 'none';
validationElement.className = 'validation-image';
// Check if password2 isn't null or undefined or empty
$('#savepasswd').prop('disabled', true);
if (password2) {
// Show the validation element
validationElement.style.display = 'inline-block';
// Choose which class to add to the element
$('#savepasswd').removeAttr('disabled');
validationElement.className +=
(password1 == password2 ? ' validation-success' : ' validation-error');
}
}
PHP代码。
$msg .= " <td><input type=\"submit\" name=\"savepasswd\" id=\"savepasswd\" value=\"Save Access\" class=\"inputadmin\"></td>\n";
答案 0 :(得分:1)
你显然没有加载jQuery。你不需要它,你可以使用普通的Javascript。
要禁用按钮:
document.getElementById('savepasswd').disabled = true;
启用按钮:
document.getElementById('savepasswd').disabled = false;