行中的链接在 Chrome 或 Firefox 中不起作用
我有一个 ASP.NET 应用程序,它从数据库中提取数据并将其放入表中。我已将其设置为如果用户单击该行中的任意位置,则链接将起作用。基本上代码是这样的:
<a href="showthisjob.aspx<tr>
<td align="left">stuff</td>
<td align="left">stuff</td>
<td align="left">stuff</td>
</tr></a>
这在 IE 中工作正常,但在 Chrome 和 Firefox 中链接不起作用。有人能告诉我为什么吗?我的学生需要在网页设计竞赛中解决这个问题。
I have an asp.net application that pulls data from a data base and puts it into a table. I have it set so that if the user clicks anywhere in the row that the link works. Basically the code is like this:
<a href="showthisjob.aspx<tr>
<td align="left">stuff</td>
<td align="left">stuff</td>
<td align="left">stuff</td>
</tr></a>
This works fine in IE but in Chrome and Firefox the link doesn't work. Can someone tell me why? My students need to fix this for a web design competition.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 HTML 标准,
不是
标记的有效子元素,
标签只能包含其他内联元素(例如
,但不包括另一个
标签)和/或文本。 IE 基本上只是更加宽容,并遵循它认为您试图做的事情,而不是您真正应该被允许做的事情。您可以尝试看看其他浏览器实际上允许您在
中填充内容并工作,但如果这是为了网页设计竞赛,我不会推荐它。
要在遵循标准的同时获得类似的功能,您可能需要使用 onClick 事件和嵌套表,或者如果您能承受学习曲线,最好使用
,因为这是为了一场比赛。如果没有,类似:
By the HTML standards, a
<tr>
is not a valid child element of an<a>
tag, an<a>
tag can only contain other in-line elements (such as a<span>
, but excluding another<a>
tag) and/or text. IE is basically just more forgiving and follows what it thinks you were trying to do instead of what you should really be allowed to do. You can experiment to see what the other browsers will actually allow you to stuff inside an<a>
and work, but if this is for a web design competition I wouldn't recommend it.To get similar functionality while following the standards, you would probably need to use an onClick event and a nested table, or better yet use
<div>
's if you can afford the learning curve since this is for a competition. If not, something like:好吧,首先,我希望您的实际代码中没有这个拼写错误:您错过了
标记的结束
>
。但实际上你不能像这样链接表。我想这与浏览器有关,事实上 IE 通常在 HTML 标准方面与其他浏览器的工作方式不同。我认为您不能将
嵌套在
上,但请告诉 Microsoft...
我建议将
在每个
内。
Well, to begin with, I hope this typo isn't in your acutal code: you missed the closing
>
for the<a>
tag.But indeed you cant link tables like that. I suppose this has to do with the browser, and the fact IE usually works different than other browsers in terms of HTML standards. I dont think you can nest
<tr>
on an<a>
, but tell that to Microsoft...I suggest putting the
<a>
inside each<td>
.