在IE和FF下稍有不同:
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns&#61;"http://www.w3.org/1999/xhtml">
<head>
<title>title>
<script type&#61;"text/Javascript">
//code from NC01 http://forums.asp.net/t/1395561.aspx
function getTableColumnValue(tableId, rowNumber, columnNumber) {
var tableRef &#61; document.getElementById(tableId);
var elementRef &#61; tableRef.rows[rowNumber].cells[columnNumber];
var elementValue &#61; &#39;&#39;;
if (elementRef.textContent) {
// Firefox
elementValue &#61; elementRef.textContent;
}
else if (elementRef.innerText) {
// IE
elementValue &#61; elementRef.innerText;
}
else {
// Default
elementValue &#61; elementRef.innerHTML;
var regExp &#61; /<\/?[^>]&#43;>/gi;
elementValue &#61; elementValue.replace(regExp, &#39;&#39;);
}
//alert(elementValue);
return elementValue;
}
script>
head>
<body>
<table border&#61;"1" id&#61;"myTable">
<tr>
<td>
aa
td>
<td>
bb
td>
<td>
cc
td>
tr>
<tr>
<td>
dd
td>
<td>
ee
td>
<td>
ff
td>
tr>
<tr>
<td>
gg
td>
<td>
hh
td>
<td>
ii
td>
tr>
table>
<input type&#61;"button" value&#61;"click" onclick&#61;"this.value&#61;getTableColumnValue(&#39;mytable&#39;,1, 2);">
body>
html>
<html xmlns&#61;"http://www.w3.org/1999/xhtml">
<head>
<title>title>
<script type&#61;"text/Javascript">
//code from NC01 http://forums.asp.net/t/1395561.aspx
function getTableColumnValue(tableId, rowNumber, columnNumber) {
var tableRef &#61; document.getElementById(tableId);
var elementRef &#61; tableRef.rows[rowNumber].cells[columnNumber];
var elementValue &#61; &#39;&#39;;
if (elementRef.textContent) {
// Firefox
elementValue &#61; elementRef.textContent;
}
else if (elementRef.innerText) {
// IE
elementValue &#61; elementRef.innerText;
}
else {
// Default
elementValue &#61; elementRef.innerHTML;
var regExp &#61; /<\/?[^>]&#43;>/gi;
elementValue &#61; elementValue.replace(regExp, &#39;&#39;);
}
//alert(elementValue);
return elementValue;
}
script>
head>
<body>
<table border&#61;"1" id&#61;"myTable">
<tr>
<td>
aa
td>
<td>
bb
td>
<td>
cc
td>
tr>
<tr>
<td>
dd
td>
<td>
ee
td>
<td>
ff
td>
tr>
<tr>
<td>
gg
td>
<td>
hh
td>
<td>
ii
td>
tr>
table>
<input type&#61;"button" value&#61;"click" onclick&#61;"this.value&#61;getTableColumnValue(&#39;mytable&#39;,1, 2);">
body>
html>