javascript - 在 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"
我想检查用户名和密码是否与我匹配regex1
并regex2
添加href
到该锚以重定向名为 FormEditor 的页面
解决方案
推荐阅读
- timestamp - 时刻js获取直到当前时间的日期
- hl7-fhir - 如何从规范生成原型文件(如 google-fhir 原型是从 FHIR 规范生成的)?
- text - 将多行文本转换为数组
- html - Bootstrap-4 justify-content-around 不适用于 flex-column
- qt - 如何在 QHBoxLayout 中对齐两个小部件,其中一个对齐最左侧,一个对齐最右侧?
- c# - EF FirstOrDefault 创建对变量的引用
- python - 函数 pgp_sym_encrypt(numeric, unknown) 不存在
- javascript - 格式化动态 html 内容...例如:{{foobar.data}}
- winforms - 拖动移动闪烁窗口的位置
- c# - 如何从结尾 c# 反转字符串 2 个字符和 2 个字符