如何将单元格的内容设置为超链接?
我用的是UltraWegGrid,我想把CODE列的内容变成超链接,
请问JavaScript如何做到?
又或者,如何按一下Button1就能将Label1的内容变成超链接,再按一下又变成非超链接?也是要求用JavaScript,无刷新实现。
------解决方案--------------------L@_@K
<!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>
<title> new document </title>
<meta name= "generator " content= "editplus " />
<meta name= "author " content= "yixianggao " />
<meta name= "keywords " content= "javascript " />
<meta name= "description " content= "csdn " />
</head>
<body>
<table border= "1 " id= "tabTest ">
<tr>
<td> Code </td>
<td> Name </td>
<td> Description </td>
</tr>
<tr>
<td> a </td>
<td> Tom </td>
<td> Good Boy </td>
</tr>
<tr>
<td> b </td>
<td> Jarry </td>
<td> Bad Boy </td>
</tr>
<tr>
<td> c </td>
<td> Marry </td>
<td> Little Girl </td>
</tr>
</table>
<input type= "button " id= "btnChangeLink " value= "Change Link " />
<input type= "button " id= "btnRecoverText " value= "Recover Text " />
</body>
<script type= "text/javascript ">
<!--
var oChange = document.getElementById( "btnChangeLink ");
var oRecover = document.getElementById( "btnRecoverText ");
var oTable = document.getElementById( "tabTest ");
// Code Column
var numColumnIndex = 0;
var strUrl = "http://community.csdn.net/ ";
oChange.onclick = function ()
{
var oRows = oTable.rows;
var oTargetCell;
var oLink;
for (var i=1; i <oRows.length; i++)
{
oTargetCell = oRows[i].cells[numColumnIndex];
if (oTargetCell.firstChild.nodeName.toLowerCase() == "#text ")
{
oLink = oTargetCell.appendChild(document.createElement( "a "));
oLink.href = strUrl;
oLink.appendChild(oTargetCell.firstChild);
}
}
};
oRecover.onclick = function ()
{
var oRows = oTable.rows;
var oTargetCell;
for (var i=1; i <oRows.length; i++)
{
oTargetCell = oRows[i].cells[numColumnIndex];
if (oTargetCell.firstChild.nodeName.toLowerCase() == "a ")
{
oTargetCell.appendChild(document.createTextNode(oTargetCell.firstChild.innerText));
oTargetCell.removeChild(oTargetCell.firstChild);
}
}
};
//-->
</script>
</html>