如何在RazorViewEngine的文本框中添加onmouseleave属性

问题描述 投票:0回答:1

我正在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上,此代码-

javascript asp.net-mvc asp.net-mvc-5 razorengine
1个回答
1
投票

[似乎您尝试将Pswd设为getElementById()时将ID定义为“ CPswd”。调用getElementById()时您会得到null,因为它不存在(由于文本不匹配)。我也会删除空间。


0
投票

似乎在尝试获取Pswd的ElementById时,您的ID定义为“ CPswd”。调用getElementById时会得到null,因为它不存在(由于文本不匹配)。我也会删除空间。

© www.soinside.com 2019 - 2024. All rights reserved.