getElementsByTagName("td") 抓不到標籤裏面的標籤

mybbb 2008-06-20 10:21:23
<html>
<head>
<meta http-equiv="Content-Language" content="zh-tw">
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>新增網頁2</title>
</head>
<body>
<div align="center">
<table border="1" width="100%" id="table3">
<tr>
<td>討論區</td>
</tr>
</table>
<table border="1" width="100%" id="table1">
<tr>
<td width="195">日期:2008/06/20 19:13</td>
<td> </td>
</tr>
<tr>
<td width="195">名稱:</td>
<td>xxxx</td>
</tr>
<tr>
<td width="195"><img src="http://l.yimg.com/tw.yimg.com/a/tw/cathy/080620_09.jpg" hspace="20"></td>
<td> </td>
</tr>
</table>
<table border="1" width="100%" id="table2">
<tr>
<td>修改</td>
</tr>
</table>
</div>
</body>
</html>

<td width="195"><img src="http://l.yimg.com/tw.yimg.com/a/tw/cathy/080620_09.jpg" hspace="20"></td>
這裡小弟不知道該如何抓值

目的要另寫個script替代原圖
<td>無name ,圖的位置 getElementsByTagName("img")[x]不是一定
我本來想用getElementsByTagName("td"),抓標籤裏面的值再另寫圖的url
請高手指教
...全文
140 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
mybbb 2008-06-21
  • 打赏
  • 举报
回复
s_liangchao1s不好意思囉
mingxuan3000比較早發

兩位大大的方法都能抓到
寫法有些微不同
都很有學習價值
在此多謝了
s_liangchao1s 2008-06-20
  • 打赏
  • 举报
回复

<html>
<head>
<meta http-equiv="Content-Language" content="zh-tw">
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>新增網頁2</title>
</head>
<body>
<div align="center">
<table border="1" width="100%" id="table3">
<tr>
<td>討論區</td>
</tr>
</table>
<table border="1" width="100%" id="table1">
<tr>
<td width="195">日期:2008/06/20 19:13</td>
<td> </td>
</tr>
<tr>
<td width="195">名稱:</td>
<td>xxxx</td>
</tr>
<tr>
<td width="195"><img src="http://l.yimg.com/tw.yimg.com/a/tw/cathy/080620_09.jpg" hspace="20"></td>
<td> </td>
</tr>
</table>
<table border="1" width="100%" id="table2">
<tr>
<td>修改</td>
</tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
alert(document.getElementById("table1").rows(2).childNodes[0].firstChild.src);
</SCRIPT>

</div>
</body>
</html>

mingxuan3000 2008-06-20
  • 打赏
  • 举报
回复

<html>
<head>
<meta http-equiv="Content-Language" content="zh-tw">
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>新增網頁2</title>
</head>
<body>
<div align="center">
<table border="1" width="100%" id="table3">
<tr>
<td>討論區</td>
</tr>
</table>
<table border="1" width="100%" id="table1">
<tr>
<td width="195">日期:2008/06/20 19:13</td>
<td> </td>
</tr>
<tr>
<td width="195">名稱:</td>
<td>xxxx</td>
</tr>
<tr><td width="195"><img src="http://l.yimg.com/tw.yimg.com/a/tw/cathy/080620_09.jpg" hspace="20"></td>
<td> </td>
</tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
alert(document.getElementById("table1").childNodes[0].childNodes[2].childNodes[0].childNodes[0].src)
</SCRIPT>
<table border="1" width="100%" id="table2">
<tr>
<td>修改</td>
</tr>
</table>
</div>
</body>
</html>
sd5816690 2008-06-20
  • 打赏
  • 举报
回复
<img id="img1" src="http://l.yimg.com/tw.yimg.com/a/tw/cathy/080620_09.jpg" hspace="20">
document.getElementById("img1").src="新的URL";

87,920

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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