使用锚提交表单是否安全? [英] Is it safe to use anchor to submit form?
问题描述
我在某处读到,使用锚标记提交表单不是很安全,所以这是我的问题:使用锚标记代替 <button>
或 提交表单?如果不是,为什么?问题是,我有一个按钮的 CSS 类,它在
<a class="button">
上显示了我想要的内容,但是如果我将它添加到实际按钮中,它会添加一个我不想要的奇怪边框.
I've read somewhere, that using anchor tag to submit a form isn't very safe, so that's my question: Is it safe, to use anchor tag instead of <button>
or <input type="submit" />
to submit a form? And if it isn't, why? The problem is, that I have a CSS class for a button, that shows what I want on <a class="button">
, but if I add it to an actual button it adds a weird border that I don't want.
谢谢
推荐答案
要使用锚点提交表单需要使用 JavaScript 来连接事件.这是不安全的,如果用户禁用了 JavaScript,您将无法提交表单.例如:
To use an anchor to submit a form would require the use of JavaScript to hook up the events. It's not safe in that if a user has JavaScript disabled, you won't be able to submit the form. For example:
<form id="form1" action="" method="post">
<a href="#" onclick="document.getElementById('form1').submit();">Submit!</a>
</form>
如果您愿意,可以使用 :
If you'd like you can use a <button>
:
<button type="submit">Submit!</button>
或者坚持我们都知道的:
Or stick with what we all know:
<input type="submit" value="Submit!" />
您可以为所有三个设置样式,但后两个不需要 JavaScript.如果您遇到边框问题,您可能只需要在某处更改一些 CSS.
You can style all three of them, but the latter two don't require JavaScript. You probably just need to change some CSS somewhere if you're having border issues.
这篇关于使用锚提交表单是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!