首页 > 解决方案 > 在 if 条件下不能通过 JQuery 方法?

问题描述

if这个 jQuery 方法 attr 在条件下不起作用

let regex1 = /^admin$/ ;
let regex2 = /^admin$/ ;
$("#ancor").click(function () { 
  if (($("#username").val() == regex1 ) && ($("#password").val() == regex2) {
    $("#ancor").attr("href", "FormEditor.html")
  } else {
    alert("username or password my be not correct")
  }  
});

我有一个锚标记,id="ancor"我想检查用户名和密码是否与我匹配regex1regex2添加href到该锚以重定向名为 FormEditor 的页面

标签: javascriptjqueryhtml

解决方案


推荐阅读