如何用js语句给下面 <table>的 <tr id="t3"> <td>333 </td> </tr> 做一个超链接
如 <table>
<tr id="t1"> <td>111 </td> </tr>
<tr id="t3"> <td>333 </td> </tr>
</table>
就是用js 给333写一个超链接.谢谢
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
<body>
<div>
<table>
<tr id="t1">
<td>
111
</td>
</tr>
<tr id="t3">
<td>
333
</td>
</tr>
</table>
</div>
</body>
</html>
<script type="text/javascript">
var tbl = document.getElementsByTagName('table')[0];
var cellText = tbl.rows[1].cells[0].innerHTML;
tbl.rows[1].cells[0].innerHTML = '';
var aobj = document.createElement('a');
aobj.setAttribute('href', 'http://blog.csdn.net/avon520');
aobj.setAttribute('target', '_blank');
aobj.appendChild(document.createTextNode(cellText));
tbl.rows[1].cells[0].appendChild(aobj);
</script>
huo
var tr = document.getElementById('t3');
tr.innerHTML = tr.innerHTML.replace(/<td>(.+)</td>/, '<td><a href="http://g.cn">$1</a></td>');