日期:2014-05-17 浏览次数:20863 次
<html>
<head>
<script type="text/javascript">
var currentTd = null;
function focusTd(td){
var txt = document.getElementById("txt1");
txt.style.width = td.offsetWidth-1;
txt.style.height = td.offsetHeight-1;
txt.style.left = td.offsetLeft;
txt.style.top = td.offsetTop;
txt.style.display = "block"
txt.value = td.innerText;
txt.focus();
txt.select();
currentTd = td;
}
function leave(){
var txt = document.getElementById("txt1");
if(currentTd != null){
currentTd.innerText = txt.value;
currentTd = null;
}
txt.style.display = "none";
}
</script>
</head>
<body>
<div id="divTest" style="width:300px; height:200px; border-style:solid; overflow-x : auto; overflow-y : auto; border-width:1px; border-color:black; background-color: pink; z-index:2">
<table border='1' width="400px" bordercolor="black" style="border-collapse:collapse">
<tr>
<th style="width:200px">aaaaa</th><th style="width:200px">bbbbb</th><th>ccccc</th><th>DDD</th><th>EEE</th>
</tr>
<tr>
<td style="width:60px" onclick="focusTd(this)">A1</td>
<td style="width:60px" onclick="focusTd(this)">B1</td>
<td style="width:60px" onclick="focusTd(this)">C1</td>
<td style="width:60px" onclick="focusTd(this)">D1</td>
<td onclick="focusTd(this)">E1</td>
</tr>
<tr>
<td style="width:60px" onclick="focusTd(this)">A2</td>
<td style="width:60px" onclick="focusTd(this)">B2</td>
<td style="width:60px" onclick="focusTd(this)">C2</td>
<td style="width:60px" onclick="focusTd(this)">D2</td>
<td onclick="focusTd(this)">E2</td>
</tr>
<tr>
<td style="width:60px" onclick="focusTd(this)">A3</td>
<td style="width:60px" onclick="focusTd(this)">B3</td>
<td style="width:60px" onclick="focusTd(this)">C3</td>
<td style="width:60px" onclick="focusTd(this)">D3</td>
<td onclick="focusTd(this)">E3</td>
</tr>
<tr>
<td style="width:60px" onclick="focusTd(this)">A4</td>
<td style="width:60px" onclick="focusTd(this)">B4</td>
<td style="width:60px" onclick="focusTd(this)">C4</td>
<td style="width:60px" onclick="focusTd(this)">D4</td>
<td onclick="focusTd(this)">E4</td>
</tr>
</table>
<input type="text" id="txt1" style="position: absolute; left: 2; top: 0; border-width:0; border-style:solid; border-color: black; z-index:1; display:none" onblur="leave()" />
</div>
</body>
<