为什么包含在<a>标签中的<input type ='button'>在IE中不起作用?

Eri*_*ric 1 html internet-explorer internet-explorer-8

此代码适用于Firefox,Chrome和Safari,但对我来说失败了(Windows)IE 8:

<a href='http://google.com'>
   <input type="button" name='go' value='go'>
</a>
Run Code Online (Sandbox Code Playgroud)

为什么?我应该使用(笨拙的)onClick事件绕过它吗?

Grrrrr ....

Men*_*ual 7

你不能有一个<button>内部<a>元素.

你可以添加一些CSS <a>看起来像一个按钮.

或者绕过它:

<input type="button" value="Google" onClick="javascript:location.href = 'http://google.com';" />
Run Code Online (Sandbox Code Playgroud)

  • +1这是无效的HTML"元素输入不能作为a元素的后代出现." [validators](http://validator.nu/)是你的朋友 (4认同)
  • `javascript:`不是必需的 - 它是`onClick`里面的javascript,而不是url (2认同)