<按钮>有什么缺点?标签? [英] What disadvantages are there to the <button> tag?
问题描述
我开始使用诊断 css 样式表,例如http://snipplr.com/view/6770/css-diagnostics--highlight-deprecated-html-with-css--more/
I started using a diagnostic css stylesheet, e.g. http://snipplr.com/view/6770/css-diagnostics--highlight-deprecated-html-with-css--more/
建议的规则之一突出显示类型为 submit 的输入标签,并建议使用 作为更语义化的解决方案.您遇到过的
类型提交(比如浏览器兼容性)的优缺点是什么?
One of the suggested rules highlights input tags with the type submit, with the recommendation to use <button>
as a more semantic solution. What are the advantages or disadvantages of <button>
with type submit (such as with browser compatibility) that you have run across?
为了清楚起见,我理解的规范,它有一个定义的开始和结束,它可以包含各种元素,而输入是一个单线,不能包含东西.我想知道的基本上是它是否坏了.我想知道当前按钮的可用程度.不幸的是,下面的第一个答案似乎暗示它在除表单之外的用途中被破坏了.
Just to be clear, I understand the spec of <button>
, it has a defined start and end, it can contain various elements, whereas input is a singlet and can't contain stuff. What I want to know essentially is whether it's broken or not. I'd like to know how usable button is at the current time. The first answer below does seem to imply that it is broken for uses except outside of forms, unfortunately.
2015 年编辑
风景变了!我现在有 6 年多的处理按钮的经验,浏览器已经从 IE6 和 IE7 转移了.所以我会添加一个答案,详细说明我的发现和我的建议.
The landscape has changed! I have 6 more years experience of dealing with button now, and browsers have somewhat moved on from IE6 and IE7. So I'll add an answer that details what I found out and what I suggest.
推荐答案
从 ASP.NET 角度回答.
Answering from an ASP.NET perspective.
当我发现这个问题时,我很兴奋 和 ModernButton 控件的一些代码,最终是一个 控件.
I was excited when I found this question and some code for a ModernButton control, which, in the end, is a <button>
control.
所以我开始添加各种这些按钮,在它们内部装饰有 <img/>
标签,使它们脱颖而出.一切都很好……在 Firefox 和 Chrome 中.
So I started adding all sorts of these buttons, decorated with <img />
tags inside of them to make them stand out. And it all worked great... in Firefox, and Chrome.
然后我尝试了 IE6 并得到检测到一个潜在危险的 Request.Form 值",因为 IE6 提交按钮内的 html,在我的情况下,其中包含 html 标签.我不想禁用 validateRequest 标志,因为我喜欢这个添加的数据验证位.
Then I tried IE6 and got the "a potentially dangerous Request.Form value was detected", because IE6 submits the html inside of the button, which, in my case, has html tags in it. I don't want to disable the validateRequest flag, because I like this added bit of data validation.
然后我写了一些javascript来在提交发生之前禁用那个按钮.在带有一个按钮的测试页面中效果很好,但是当我在具有其他 <button>
标签的真实页面上尝试时,它又炸了.因为 IE6 提交所有按钮的 html.所以现在我有各种代码在提交之前禁用按钮.
So then I wrote some javascript to disable that button before the submit occurred. Worked great in a test page, with one button, but when I tried it out on a real page, that had other <button>
tags, it blew up again. Because IE6 submits ALL of the buttons' html. So now I have all sorts of code to disable buttons before submit.
IE7 也有同样的问题.谢天谢地,IE8 修复了这个问题.
Same problems with IE7. IE8 thankfully has this fixed.
哎呀.如果您使用的是 ASP.NET,我建议不要走这条路.
Yikes. I'd recommend not going down this road IF you are using ASP.NET.
更新:
我发现了一个看起来很有希望解决这个问题的图书馆.
I found a library out there that looks promising to fix this.
如果您使用此库中的 ie8.js 脚本:http://code.google.com/p/ie7-js/
If you use the ie8.js script from this library: http://code.google.com/p/ie7-js/
可能效果还不错.IE8.js 通过按钮标签使 IE5-7 与 IE8 保持同步.它使提交的值成为真正的值,并且只有一个按钮被提交.
It might work out just fine. The IE8.js brings IE5-7 up to speed with IE8 with the button tag. It makes the submitted value the real value and only one button gets submitted.
这篇关于<按钮>有什么缺点?标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!