area
标记上的 nohref
属性会导致区域从图像映射中明确排除。它适用于 IE 6-7,因为当鼠标悬停在标记为此类的区域上时,您可以看到鼠标指针没有改变。矩形有一个“nohref”,而蓝色圆圈没有。
但是,我无法找到任何方法可以在 IE 6 和 7 中运行的 Javascript 中以编程方式测试它。无论属性是否为,getAttribute
总是返回 false
存在或不存在。 jQuery .attr
也不起作用。
最佳答案
由 XHTML standard ,nohref 属性应写为 nohref="nohref"
。如果这样做,您可以轻松测试它,因为 .attr('nohref')
将返回字符串 "nohref"
。
但是,HTML5 不再支持此属性。来自 W3C working draft :
The nohref attribute on the area element is obsolete. Omitting the href attribute is sufficient.
因此您可以通过 if($('area').attr('href')){/* href is set */}
进行测试。
关于javascript - 如何测试 IE6/7 中是否存在 "nohref"属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6230175/