我正在ASP.Net MVC5中工作,我想使用Javascript将密码字段与确认密码匹配,但是由于它使用Razor View Engine,因此我无法在textbox
上添加onmouseleave属性。请预先提供帮助。
@Html.EditorFor(model => model.ConfirmedPassword, new { htmlAttributes = new { @class = "form-control", @id = " CPswd", @onmouseleave = "Show();" } })
这给我这个错误-
CreateUser:122未捕获的TypeError:无法在以下位置的Show(CreateUser:122)处读取null的属性“值”HTMLInputElement.onmouseleave(CreateUser:105)显示@ CreateUser:122onmouseleave @ CreateUser:105
在Createuser122处是此代码-
var pswd = document.getElementById('Pswd').value;
在CreateUser105上,此代码-
[似乎您尝试将Pswd设为getElementById()
时将ID定义为“ CPswd”。调用getElementById()
时您会得到null,因为它不存在(由于文本不匹配)。我也会删除空间。
似乎在尝试获取Pswd的ElementById时,您的ID定义为“ CPswd”。调用getElementById时会得到null,因为它不存在(由于文本不匹配)。我也会删除空间。