简体   繁体   中英

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.

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? - 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.

But when not using <form> with <input> s but just simple <button> the code would be cleaner. And nowadays many pages need JS to be running. Who switches JS off?

So should I bother to provide no-JS functionality at all?

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.

In my opinion, it's perfectly acceptable to require javascript these days. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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