我一直在寻找在互联网上的解决方案,为什么IE7是不是如正常打开链接CSS按钮没有在IE工作,但确实在FF
<a href="http://www.google.com"><button class="class1">Google</button></a>
IE7是否不喜欢有?
我听说我应该为此使用jquery吗?但没有人链接到任何文章。
我一直在寻找在互联网上的解决方案,为什么IE7是不是如正常打开链接CSS按钮没有在IE工作,但确实在FF
<a href="http://www.google.com"><button class="class1">Google</button></a>
IE7是否不喜欢有?
我听说我应该为此使用jquery吗?但没有人链接到任何文章。
根据W3C的anchor (<a>
) tags和<button>
tags规格,你应该能够做到这一点很好,但是according to a quick Google search,您不能和/或不应该这样做,并且它在Internet Explorer中不起作用。
This article居然建议添加JavaScript,因此该链接可以在IE也将拉开:
<a href="http://www.expertsguide.info/"><button type="button" onclick="window.location('http://www.expertsguide.info/')">Click Me to go to Experts Guide</button></a>
你最好不要在超链接中使用按钮。
将超链接设置为按钮样式。
尝试这些
虽然你可以,你不应该有内部的锚(<a>
)按钮(<button>
)。
添加事件处理程序的按钮,像这样:
<input type="button" value="Google" onClick="javascript:location.href = 'http://google.com';" />
注意:你应该认为不这样做,对于各种各样的原因。底线你可以(也应该)将你的<a>
元素看起来像一个按钮。
根据W3C,可以有形式的元件(其包括''
@Nightfirecat你说得对。它可以完成,但不应该完成。据此编辑。 – Joao
试试这个:
<script>
$(document).ready(function() {
$('.class1').click(function() {
window.location = $(this).parent().attr('href');
return false;
}
});
</script>
或者干脆删除按钮标签和使用:
<script>
$(document).ready(function() {
$('a').click(function() {
window.location = $(this).attr('href');
return false;
}
});
</script>
要JavaScript的独立(因此它也适用于浏览器与JS禁用,在出乎很多其他的答案在这里),我建议用普通的方法将它包装在<form>
中,并改为<button type="submit">
(或<input type="submit">
)。
<form action="http://www.google.com">
<button type="submit" class="class1">Google</button>
</form>
或
<form action="http://www.google.com">
<input type="submit" value="Google" class="class1" />
</form>
谢谢,这是我使用的解决方案,除了某些原因,它必须是window.location.href ...怪异不是吗? – Matt