是否有“默认动作”的标准资源的HTML元素? [英] Is there a standard resource for the "default action" of HTML elements?

查看:141
本文介绍了是否有“默认动作”的标准资源的HTML元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一个定义的标准,默认的操作是各种HTML元素。我查看了 W3C的HTML规范和虽然它们非常精确,可以使用什么属性与元素(以及一些行为的东西,如正式包含在表单提交中),没有关于元素的行为。我还检查了 Mozilla JS参考资料,并没有发现任何内容。

I'm wondering if there is a defined standard for what the default action is of various HTML elements. I've looked at the W3C's HTML specification and while they are very precise with what attributes can be used with elements (and also some behavioural stuff such as exactly what gets included with form submission) there's nothing about the behaviour of elements. I've also checked out the Mozilla JS reference, and found nothing there either.

特别是我正在寻找表单提交按钮的默认行为;我在不同的地方看到,它的默认操作是提交表单,或者默认的操作是不提交表单,而是获取焦点。因此,对于提交按钮的 onclick =return false;是否会停止提交表单似乎没有一致意见。

In particular I'm looking for the default behaviour of a form submit button; I've seen in different places that its default action is to submit the form and alternatively that its default action is not to submit the form but rather to get focus. Accordingly, there seems to be no consensus on whether onclick="return false;" for a submit button will stop form submission or not.

(为了清楚起见,编辑 - 我不想对提交的 onclick 或任何类似的内容进行任何表单级验证;如果我是,我'不要使用表单的 onsubmit ,我真的很有兴趣在按钮上捕获点击,并且可能没有在这种情况下提交表单,这可能会要求按钮的 onclick 设置表单的 onsubmit 检查的状态,但如果我只能返回那么这样很好,即使没有,那么关键是什么命令 onsubmit onclick 处理程序被解雇(即按钮是否在运行点击处理程序之前发送提交),这再次我还没有看到在任何地方指定。)

(Edit for clarity - I'm not trying to do any form-level validation on the submit's onclick or anything like that; if I were, I'd be using the form's onsubmit instead. I really am specifically interested in catching clicks on the button and potentially not having it submit the form in this case. This might end up requiring the button's onclick set some state that the form's onsubmit inspects, but if I can just return false then that's great. Even if not, it would then be critical what order the onsubmit and onclick handlers get fired (i.e. does the button dispatch the submit before running its click handler?) which again I haven't seen specified anywhere.)

只需编写一个测试,我宁愿依赖于规范/记录的行为,而不是一个简单的测试的结果,无疑会错过任何细微之处,如果它们存在。特别是,我上周进行了一个快速测试,似乎表明它没有停止表单提交,但是今天运行的一个表示它 。我没有运气找到任何一种权威资源,当您与其元素交互时,实际执行哪些浏览器(例如,默认操作是什么,提交按钮的onclick处理程序是否在之前或之后触发表单提交调度等)

While it would be simply to code up a test, I'd rather rely on specs/documented behaviour rather than the results of a trivial test that would undoubtedly miss any subtleties should they exist. In particular, I ran a quick test last week that seemed to show it didn't stop form submission, but running one today shows that it does. I have had no luck finding any sort of authoritative resource as to what browsers actually do when you interact with their elements (e.g. what the default action is, whether the onclick handler for a submit button fires before or after the form submission dispatch, etc.)

欢迎任何有关在这种情况下查看的建议。

Any advice as to where to look in this case would be welcome.

推荐答案

相关文件是 DOM3活动 HTML 5规范

他们可能没有您需要的所有信息,但应该。因此,如果您发现缺少这些行为,请请求指定这些行为

They might not have all information you need, but should. So if you find them lacking, please request those behaviors to be specified.

这篇关于是否有“默认动作”的标准资源的HTML元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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