我们为什么还要在html中使用form元素? [英] Why should we still use form element in html?

查看:116
本文介绍了我们为什么还要在html中使用form元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用现代javascript(以及js框架!)以及执行同步/异步操作(POST,GET等等)的不同方法,我仍然想知道为什么还要使用表单元素?

With modern javascript (and js framework too!) and different ways to do a sync/async actions (POST, GET etc,..) I am still wondering why would one still want to use form element?

这是由于代码语义和实际指定提交内容的区域吗?

Is it due to code semantics and actually "specifying" an area from which something is submitted?

是否因为表单行为作为帮助收集(我会说不好)的数据?

Is it because form acts as a helper that "collects" (poorly I would say) data?

以上所有都可以在javascript中轻松完成,所以我想不出任何其他原因使用表格提交数据?

All of the above can be easily done in javascript, so I cannot think of any other reason for using form for submitting data?

推荐答案

渐进式增强的rel =noreferrer>不引人注目的JavaScript 仍在继续最佳实践,因为有很多情况下 JavaScript失败

Writing unobtrusive JavaScript that works using progressive enhacement continues to be best practise because there are plenty of circumstances where JavaScript fails.

除此之外,仅仅因为你可以用JavaScript做某事并不意味着你应该用JavaScript做点什么。通常,常规表单提交将以较少的工作提供所有期望的效果。

Aside from that, just because you can do something with JavaScript doesn't mean you should do something with JavaScript. Often a regular form submission will give all the desired effects with less work.

除此之外,表单是收集数据的有用元素,即使您这样做使用JavaScript。例如,您可以使用表单元素填充 FormData 元素。

And on top of that, a form is a useful element to collect data with even if you do use JavaScript. For example, you can use a form element to populate a FormData element.

表单为组表单提供语义数据屏幕阅读器大量使用这些控件。

Forms provide semantic data to group form controls, this is heavily used by screen readers.

如评论中所述,一些密码管理器使用它们来识别分组登录表单控件。

As mentioned in comments, some password managers use them to identify grouped login form controls.

这篇关于我们为什么还要在html中使用form元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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