应该是HTML Anchor标签荣誉被禁用的属性? [英] Should the HTML Anchor Tag Honor the Disabled Attribute?

查看:245
本文介绍了应该是HTML Anchor标签荣誉被禁用的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建一个HTML锚点标签并将 disabled 属性设置为true,我会在不同的浏览器中获得不同的行为(惊喜!惊喜!)。



我创建了一个小提琴来演示。



在IE9中,链接显示为灰色,不会传输到HREF位置。
在Chrome / FF / Safari中,链接是正常的颜色,并将传输到HREF位置。



应该是什么正确的行为?是IE9呈现这不正确,我应该实现一些CSS和javascript来修复它;或者Chrome / FF / Safari不正确,最终会赶上吗?



提前感谢。



查看HTML5规格


IDL属性禁用仅适用于样式表链接。当
link元素定义样式表链接时,禁用的属性
的行为与替换样式表DOM所定义的相同。对于所有其他
链接元素,它总是返回false,并且不会设置。


http://dev.w3.org/html5/spec/Overview.html#the-link-element



HTML4规格甚至没有提及 disabled



http://www.w3.org/TR/html401/struct/links.html #h-12.2



编辑



方法来获得这种效果的跨浏览器是js / css如下:

  #link {
text-decoration:没有;
color:#ccc;
}

js

  $('#link')click(function(e){
e.preventDefault();
});

示例: http://jsfiddle.net/jasongennaro/QGWcn/


If I create an HTML anchor tag and set the disabled attribute to true, I get different behaviors in different browsers (surprise! surprise!).

I created a fiddle to demonstrate.

In IE9, the link is grayed out and does not transfer to the HREF location. In Chrome/FF/Safari, the link is the normal color and will transfer to the HREF location.

What should the correct behavior be? Is IE9 rendering this incorrectly and I should implement some CSS and javascript to fix it; or is Chrome/FF/Safari not correct and will eventually catch up?

Thanks in advance.

解决方案

IE appears to be acting incorrectly in this instance.

See the HTML5 spec

The IDL attribute disabled only applies to style sheet links. When the link element defines a style sheet link, then the disabled attribute behaves as defined for the alternative style sheets DOM. For all other link elements it always return false and does nothing on setting.

http://dev.w3.org/html5/spec/Overview.html#the-link-element

The HTML4 spec doesn't even mention disabled

http://www.w3.org/TR/html401/struct/links.html#h-12.2

EDIT

I think the only way to get this effect cross-browser is js/css as follows:

#link{
    text-decoration:none;
    color: #ccc;
}

js

$('#link').click(function(e){
    e.preventDefault();
});

Example: http://jsfiddle.net/jasongennaro/QGWcn/

这篇关于应该是HTML Anchor标签荣誉被禁用的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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