如何让外层的标签起作用

佛曰我不想说话 2008-06-18 11:25:08
有下面这段HTML代码,现在已经有了标签<a id=a1>存在。我希望在a1外面再添加一个<a>标签,当我惦记里面jpg。jpg的时候会连接到外面的a2对应的地址.
但是当两个<A>叠加的时候总是内层的<A>起作用,我怎么能让外层的<A>起作用呢?
<A1>里面是不能修改的。
<table>
<tr><td>
<a id=a2 href="http://www.sina.com.cn">
<a id=a1 href="http://www.126.com">
<img border=0 ALT="blah blah blah" SRC="http://b/t/JPG.jpg">
</a>
</a>
</td></tr>
</table>
...全文
101 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
familyX 的办法好用,多谢了
familyX 2008-06-18
  • 打赏
  • 举报
回复
或者:

<table>
<tr> <td onmouseover="document.getElementById('a1').href=document.getElementById('a2').href">
<a id=a2 href="http://www.sina.com.cn">
<a id=a1 href="http://www.126.com">
<img border=0 ALT="blah blah blah" SRC="http://b/t/JPG.jpg">
</a>
</a>
</td> </tr>
</table>
familyX 2008-06-18
  • 打赏
  • 举报
回复

<table>
<tr> <td onmouseover="document.getElementById('a1').href='http://www.sina.com.cn'">
<a id=a2 href="http://www.sina.com.cn">
<a id=a1 href="http://www.126.com">
<img border=0 ALT="blah blah blah" SRC="http://www.doulaicha.com/images/logo1.jpg">
</a>
</a>
</td> </tr>
</table>
familyX 2008-06-18
  • 打赏
  • 举报
回复

<table>
<tr> <td>
<a id=a2 href="http://www.sina.com.cn">
<a id=a1 href="http://www.126.com">
<img border=0 ALT="blah blah blah" onclick="document.getElementById('a1').href=document.getElementById('a2').href" SRC="http://www.doulaicha.com/images/logo1.jpg">
</a>
</a>
</td> </tr>
</table>
bieyinan 2008-06-18
  • 打赏
  • 举报
回复
只要一个A,把HREF的值当成一个变量就可以了
<table>
<tr> <td>
<a id=a1 href="<%=url%>">
<img border=0 ALT="blah blah blah" SRC="http://b/t/JPG.jpg">
</a>
</td> </tr>
</table>
  • 打赏
  • 举报
回复
<script>
document.onclick=mouseClick;
function mouseClick(){
document.getElementById('a1').href=document.getElementById('a2').href;
}
</script>
<a id='a2' href="http://www.sina.com.cn">
<a id='a1' href="http://www.126.com">
<img border=0 ALT="blah blah blah" SRC="http://b/t/JPG.jpg">
</a>
</a>
</td> </tr>
</table>

这个方法比较好,不需要修改任何你原来的任何代码
  • 打赏
  • 举报
回复
<table> 
<tr> <td>
<a id=a2 href="http://www.sina.com.cn">
<a id=a1 href="http://www.126.com">
<img border=0 ALT="blah blah blah" onclick="document.getElementById('a1').href=document.getElementById('a2').href" SRC="http://b/t/JPG.jpg">
</a>
</a>
</td> </tr>
</table>

就这样就可以了
  • 打赏
  • 举报
回复
[Quote=引用楼主 GetDC 的帖子:]
有下面这段HTML代码,现在已经有了标签 <a id=a1>存在。我希望在a1外面再添加一个 <a>标签,当我惦记里面jpg。jpg的时候会连接到外面的a2对应的地址.
但是当两个 <A>叠加的时候总是内层的 <A>起作用,我怎么能让外层的 <A>起作用呢?
<A1>里面是不能修改的。
<table>
<tr> <td>
<a id=a2 href="http://www.sina.com.cn">
<a id=a1 href="http://www.126.com">
<img border=0 ALT="blah blah blah" SRC="http://b/t…
[/Quote]
这个简单啊

<img border=0 ALT="blah blah blah" SRC="http://b/t…
加一个点击事件
popule_daisy 2008-06-18
  • 打赏
  • 举报
回复
<table>
<tr> <td>
<a id=a2 href="http://www.sina.com.cn">
<a id=a1 href="http://www.126.com">
<img border=0 ALT="blah blah blah" onclick="document.getElementById('a1').href=document.getElementById('a2').href" SRC="http://b/t/JPG.jpg">
</a>
</a>
</td> </tr>
</table>

祝楼主好运!
「已注销」 2008-06-18
  • 打赏
  • 举报
回复
使用javascript,应该可以修改a1。

href是a的属性……。

@_@

61,115

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧