name='' 的无效表单控件不可聚焦 [英] An invalid form control with name='' is not focusable

查看:28
本文介绍了name='' 的无效表单控件不可聚焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在谷歌浏览器中,一些客户无法进入我的付款页面.尝试提交表单时出现此错误:

In Google Chrome some customers are not able to proceed to my payment page. When trying to submit a form I get this error:

name='' 的无效表单控件不可聚焦.

An invalid form control with name='' is not focusable.

这是来自 JavaScript 控制台.

This is from the JavaScript console.

我读到问题可能是由于隐藏字段具有 required 属性.现在的问题是我们使用的是 .net webforms required 字段验证器,而不是 html5 required 属性.

I read that the problem could be due to hidden fields having the required attribute. Now the problem is that we are using .net webforms required field validators, and not the html5 required attribute.

谁收到这个错误似乎是随机的.有没有人知道解决方案?

It seems random who gets this error. Is there anyone who knows a solution for this?

推荐答案

如果表单字段验证失败,Chrome 上会出现此问题,但由于相应的无效控件不可聚焦,浏览器尝试显示消息 请填写此字段" 旁边的内容也失败了.

This issue occurs on Chrome if a form field fails validation, but due to the respective invalid control not being focusable the browser's attempt to display the message "Please fill out this field" next to it fails as well.

由于多种原因,表单控件在触发验证时可能无法获得焦点.下面描述的两种情况是最突出的原因:

A form control may not be focusable at the time validation is triggered for several reasons. The two scenarios described below are the most prominent causes:

  • 根据业务逻辑的当前上下文,该字段无关紧要.在这种情况下,相应的控件应该被禁用或从 DOM 中删除,或者此时不使用 required 属性进行标记.

由于用户在输入上按下 ENTER 键,可能会发生过早验证.或者用户点击了表单中的按钮/输入控件,但没有正确定义控件的 type 属性.如果按钮的 type 属性未设置为 button,Chrome(或任何其他浏览器)会在每次按钮被点击是因为 submit 是按钮的 type 的默认值> 属性.

Premature validation may occur due to a user pressing ENTER key on an input. Or a user clicking on a button/input control in the form which has not defined the type attribute of the control correctly. If the type attribute of a button is not set to button, Chrome (or any other browser for that matter) performs a validation each time the button is clicked because submit is the default value of a button's type attribute.

要解决此问题,如果您的页面上有一个按钮可以执行除提交重置之外的其他操作,永远记住这样做:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆