提交带有锚点的表单 + javascript - 不好的做法?
我目前有两个锚标记发送 url 查询以将选票放入数据库中,但我想切换到使用表单来保持 url 干净并避免重复查询(不是真正的问题,但使其看起来很难看)。
现在锚点需要在内部包含一个span标签,以通过css向按钮(链接)添加额外的背景元素,因此我不能使用常规的表单按钮。
您是否认为使用 javascipt 从锚点提交这些表单是不好的做法?我可以想到其他一些解决方案,但它们似乎都不值得麻烦。我是否应该保留一个无脚本回退,让禁用 javascript 的用户可以发送 url 查询(我真的想完全避免 url 查询)?如果,那么如何最好地执行呢?
谢谢,
西蒙.
I currently have two anchor tags sending url queries to put votes inside a database, but i want to switch to using forms to keep the urls clean and avoid duplicate queries (not really an issue, but makes it look ugly).
Now the anchors need to contain a span-tag inside to add additional background elements to the buttons (links) through css, therefore I can't use regular form-buttons.
Do you consider submitting these forms from the anchors with javascipt as bad practice? I can think of some other solutions, but they all doesn't seem worth the trouble. Should I keep a no-script fallback where users with javascript disabled get to send url queries instead (i really want to avoid url queries altogether)? If, then how would this best be executed?
Thanks,
Simon.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在表单中使用
您可以使其看起来与现在的
完全相同,但单击它将提交一个 POST 表单。就好像我们有一个可以进行 POST 操作的
!
you can use
<button>
in your form. it can contain content, and you can style it as you like.you can make it look exactly as the
<a>
you have now, but clicking it will submit a POST form. It is almost as if we have a<a>
that does POST!以这种方式制作按钮应该可行:
您应该尽量不要使用 JavaScript 提交表单,或者至少确保该功能在关闭时可用。
Doing your buttons this way should work:
You should endeavor to never submit a form with JavaScript, or at the very least, ensure that the functionality is available when it is turned off.
我建议使用普通表单提交按钮。
您可以将 CSS 应用于按钮以使其看起来时尚或应用背景图像。
我不认为你的做法是不好的做法。但对于使用 No-Script for Firefox 等附加组件的用户来说,该表单将会被破坏。
I would recommend using the normal form submit button.
You can apply CSS to the button to make it look stylish or apply a background image.
I do not think the way you did it is a bad-practice. But the form will break for users who use add-ons like No-Script for Firefox.