简体   繁体   English

表单可访问性-按钮上的操作

[英]Forms accessibility - actions on buttons

I have a Shopping Cart and for example there is a <button> that will trigger an action to add an item to the cart. 我有一个购物车,例如有一个<button> ,它将触发将商品添加到购物车的操作。

And my dilemma is: - should I just have a standalone button with JS hook that sends a POST request to an API to add/update an item to cart? 我的难题是:-我是否应该只有一个带有JS挂钩的独立按钮,该按钮将POST请求发送到API,以将商品添加/更新到购物车? - or should I wrap it in a <form> with hidden <input> s and then when there is no JS the button will be working because form will be submitted and when JS enabled I will submit the form via JS. -或者我应该将其包装在带有<input>隐藏的<form> ,然后当没有JS时该按钮将起作用,因为将提交表单,并且当启用JS时,我将通过JS提交表单。

But when not using <form> with <input> s but just simple <button> the code would be cleaner. 但是,当不将<form><input> <form>一起使用,而只是简单的<button> ,代码将更简洁。 And nowadays many pages need JS to be running. 如今,许多页面都需要JS才能运行。 Who switches JS off? 谁关闭JS?

So should I bother to provide no-JS functionality at all? 那么,我应该完全不提供无JS功能吗?

Maybe I should bother only for public sector websites to provide it? 也许我应该只为公共部门网站提供它?

In my case JS would not be an enhancement but replacement for the default form functionality as you see. 就我而言,JS不是增强功能,而是您所看到的默认表单功能的替代品。

In my opinion, it's perfectly acceptable to require javascript these days. 在我看来,这几天需要javascript是完全可以接受的。 It may even provide a better and more accessible user experience in some cases. 在某些情况下,它甚至可以提供更好和更易于访问的用户体验。

That being said, it's also very important to provide graceful fall-backs for clients that don't have javascript enabled for whatever reason. 话虽如此,为无论出于何种原因未启用javascript的客户端提供优美的备用信息也很重要。 In the very minimum, there should be some sort of a warning or alert letting the user know that basic functionality won't work without Javascript. 最起码,应该有某种警告或警报,让用户知道没有Javascript无法使用基本功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM