dongmu6225 2016-02-23 01:08
浏览 328
已采纳

Ajax按钮启用/禁用

How do I enable and Disable the button with AJAX get error admin.php:15 Uncaught ReferenceError: $ is not defined

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 code.

$msg .= "  <td><input type=\"submit\" name=\"savepasswd\"  id=\"savepasswd\" value=\"Save Access\" class=\"inputadmin\"></td>
";
  • 写回答

1条回答 默认 最新

  • dsf55s1233 2016-02-23 01:21
    关注

    You apparently don't have jQuery loaded. You don't need it just for this, you can use plain Javascript.

    To disable the button:

    document.getElementById('savepasswd').disabled = true;
    

    To enable the button:

    document.getElementById('savepasswd').disabled = false;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办