IE中的struts验证问题
我正在使用 Struts 2.1.8 并在 IE 中面临验证问题。我收到以下错误,
An exception occurred: Error. Error message: Invalid argument.
我尝试找出原因并发现以下内容。我生成的 javascript 代码是:
field = form.elements['district.name'];
var error = "Enter only alphabets for district";
if (continueValidation && field.value != null && !field.value.match("^[a-zA-Z ]*$")) {
addError(field, error);
errors = true;
}
我尝试通过将相同的代码放入函数中并在 onclick 事件中调用它来进行模拟。 addError()
方法抛出异常,原因是 field
变量。如果我将其更改为 field[0]
,它就可以正常工作。如何修复这个错误?
I am using Struts 2.1.8 and facing validation problem in IE. I am getting the following error
An exception occurred: Error. Error message: Invalid argument.
I tried out to figure out the cause and found the following. My generated javascript code is:
field = form.elements['district.name'];
var error = "Enter only alphabets for district";
if (continueValidation && field.value != null && !field.value.match("^[a-zA-Z ]*$")) {
addError(field, error);
errors = true;
}
I tried to mock up by putting the same code in a function and calling it in onclick event. The method addError()
throws the exception and the reason is field
variable. If I change it to field[0]
, it works fine. How to fix this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查生成的 HTML 源。在网络浏览器中打开页面,右键单击并选择查看源代码。输入字段的名称真的是
district.name
吗?它不是像许多其他 MVC 框架一样以其他一些自动生成的键(可能是Check the generated HTML source. Open the page in webbrowser, rightclick and choose View Source. Is the input field's name really
district.name
? Isn't it prefixed/suffixed with some other autogenerated key (possibly the ID/name of the<form>
) like as many other MVC frameworks do? If so, you'll need to change the JavaScript code accordingly that it uses the right element name as it appears in the HTML DOM tree. You know, JavaScript runs at the client machine and only sees the generated HTML DOM tree, not the "original" server-side code which is responsible for generating the HTML.