< button>有什么缺点。标签? [英] What disadvantages are there to the <button> tag?

查看:381
本文介绍了< button>有什么缺点。标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用诊断css样式表,例如
http:/ /snipplr.com/view/6770/css-diagnostics--highlight-deprecated-html-with-css--more/



其中一个建议规则突出显示具有类型提交的输入标签,并建议使用< button> 作为更多的语义解决方案。这是一个新的标签给我,你们推荐它,还是有缺点(如与浏览器兼容性),你经历了?



只是为了清楚,我理解< button> 的规范,它有一个定义的开始和结束,它可以包含各种元素,而input是一个单例,不能包含东西。我想知道的基本上是是否破碎。所以尽管从来没有使用它,我很想开始使用它,我只是不知道它在现实世界中是如何工作。



2015年的编辑



景观已经改变!我有6年以上的处理按钮的经验,现在的浏览器有点移动从IE6和IE7。因此,我将补充一个答案,详细说明我发现的内容和我的建议。

解决方案



当我发现这个问题和一些用于ModernButton控件的代码,最后是一个< button> 控件。



所以我开始添加各种类型的按钮,用< img /> 他们让他们脱颖而出。然后我试过IE6,并得到一个潜在危险的Request.Form值被检测到,因为IE6提交html里面的按钮,在我的case,有html标签。我不想禁用validateRequest标志,因为我喜欢这个添加位的数据验证。



然后我写了一些javascript,在提交之前禁用该按钮。在一个测试页面中使用一个按钮,但是当我试图在一个真实的页面,有其他< button> 标签,它再次爆炸。因为IE6提交了所有的按钮的html。所以现在我有各种代码在提交之前禁用按钮。



与IE7相同的问题。 IE8很高兴有这个固定的。



Yikes。如果您使用ASP.NET,我建议您不要这样做。



更新:



我发现一个看起来很有希望修复这个问题的库。



如果你使用这个库中的ie8.js脚本: http:// code .google.com / p / ie7-js /



它可能工作得很好。 IE8.js带来IE5-7加速与IE8与按钮标签。它使提交的值为真实值,只有一个按钮被提交。


I started using a diagnostic css stylesheet, e.g. http://snipplr.com/view/6770/css-diagnostics--highlight-deprecated-html-with-css--more/

One of the suggested rules highlights input tags with the type submit, with the recommendation to use <button> as a more semantic solution. This is a new tag to me, do you guys recommend it, or are there disadvantages (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. So despite never having used it before, I'd love to start using it, I just don't know how well it works in the real world. The first answer below does seem to imply that it is broken for uses except outside of forms, unfortunately.

Edit for 2015

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.

解决方案

Answering from an ASP.NET perspective.

I was excited when I found this question and some code for a ModernButton control, which, in the end, is a <button> control.

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.

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.

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.

Same problems with IE7. IE8 thankfully has this fixed.

Yikes. I'd recommend not going down this road IF you are using ASP.NET.

Update:

I found a library out there that looks promising to fix this.

If you use the ie8.js script from this library: http://code.google.com/p/ie7-js/

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.

这篇关于&lt; button&gt;有什么缺点。标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆