开发者

Why use buttons & forms for submitting a piece of data, when just icon image with onclick handling function may work as well?

开发者 https://www.devze.com 2023-04-01 01:38 出处:网络
Why use buttons within form for submitting a piece of data (such as for favorite-ing an question here on SO), when simply icon image with on-click JS handler function may work as well ?

Why use buttons within form for submitting a piece of data (such as for favorite-ing an question here on SO), when simply icon image with on-click JS handler function may work as well ?

Here the buttons I am referring to are like 'Vote-up' buttons, or 'Favorite a question' buttons on stack overflow. & not the Submit an answer button for which I would defintiely use forms and buttons.

I would like to sim开发者_运维知识库ply put the icon images in place of my 'vote up' or 'favrorite' buttons and attach a click event handling function which would update my server via ajax. The reason being this reduces & cleans-up my markup


EDIT :

I guess most of the biggest sites today like fb/ twitter etc are relying on JS & as I have just noticed they dont provide a alternate way for some of the most basic features like liking a post when javascript is disabled. I obviously dont need to go beyond those users. Thus by limiting myself to JS enabled users I think I would be quite OK.


The vote-up & favorite button are anchor tags on stackoverflow (or I don't see what you're talking about!).

Also, I think it is better to use forms so that it degrades gracefully without JS.


I'd use an ajax post request for that, definitely. I think you're right. Use $.ajax or the shortcut $.post on the click event for the image. A loading effect is also important in terms of UX.


Why use buttons within form for submitting a piece of data (such as for favorite-ing an question here on SO), when simply icon image with on-click JS handler function may work as well ?

It might work. It might not work. HTML is solid and reliable. Build on things that work and don't fall foul of the Gawker problem

0

精彩评论

暂无评论...
验证码 换一张
取 消