Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript-禁用提交按钮_Javascript_Submit_Getelementbyid - Fatal编程技术网

JavaScript-禁用提交按钮

JavaScript-禁用提交按钮,javascript,submit,getelementbyid,Javascript,Submit,Getelementbyid,我的函数无法禁用submit按钮(id=“mySubmit”),其余功能正常。(该函数在“onkeyup”上调用) 如果两个密码字段的值不匹配,我将尝试禁用它 功能检查\u匹配(){ var pw1=document.getElementById(“一”)值; var pw2=document.getElementById(“两个”).value; 如果(pw1==pw2){ document.getElementById(“错误匹配”).style.color=“绿色”; document.

我的函数无法禁用submit按钮(id=“mySubmit”),其余功能正常。(该函数在“onkeyup”上调用)

如果两个密码字段的值不匹配,我将尝试禁用它

功能检查\u匹配(){
var pw1=document.getElementById(“一”)值;
var pw2=document.getElementById(“两个”).value;
如果(pw1==pw2){
document.getElementById(“错误匹配”).style.color=“绿色”;
document.getElementById(“error_match”).innerHTML=“paswords match”;
document.getElementById(“mySubmit”).disabled=false;
}否则{
document.getElementById(“错误匹配”).style.color=“红色”;
document.getElementById(“error_match”).innerHTML=“密码不匹配”;
document.getElementById(“mySubmit”).disabled=true;
}
}

电子邮件
紫苏
重复密码

已接受
登记
您只需使用===代替==

3=='3'//true-因为值相同 3=='3'//false-因为数据类型不同


始终使用===strict equal

您的代码正在相应地工作。即使值不匹配,我仍然可以提交表单检查现在编辑的问题,没有问题,它按预期工作。当按钮被禁用时,您如何提交?最多可以与
===
进行比较,而不是
=