选中内容,请看代码
-----------------
<script>
var bFocus = false;
function keydown2(control)
{
var code = event.keyCode;
if(event.keyCode==13)
{
event.keyCode=9;
return true;
}
var the_obj = event.srcElement;
var the_td = get_Element(event.srcElement,"td");
if(the_td==null) return;
var the_tr = the_td.parentElement;
var the_table = get_Element(the_td,"table"); var cur_row = the_tr.rowIndex;
var cur_col = the_td.cellIndex;
if (code==38)
{
//alert("up");
cur_row = cur_row-1;
if (cur_row > -1)
{
var a = the_table.rows[cur_row].cells[cur_col].childNodes[0];
if (a.type=="text")
{
var r =a.createTextRange();
r.collapse();
r.select();
bFocus = true;
}
}
}
return true;
}function get_Element(the_ele,the_tag){
the_tag = the_tag.toLowerCase();
if(the_ele.tagName.toLowerCase()==the_tag)return the_ele;
while(the_ele=the_ele.offsetParent){
if(the_ele.tagName.toLowerCase()==the_tag)return the_ele;
}
return(null);
}</script>
<form method="post" action="abc.asp" name="form1">
<p> </p>
<p>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="1">
<TR>
<TD><input id="111" type="text" name="T11" onkeydown="return keydown2(this);" tblId="t01" onfocus="if(bFocus == true) {this.select();bFocus = false;}"></TD>
<TD><input id="222" type="text" name="T12" onkeydown="return keydown2(this);" tblId="t02"></TD>
</TR>
<TR>
<TD><input id="333" type="text" name="T13" onkeydown="return keydown2(this);" tblId="t11"></TD>
<TD>
<input id="444" type="text" name="T14" onkeydown="return keydown2(this);" tblId="t12">
</TD>
</TR>
</TABLE>
</p>
<p> </p>
<p>&
-----------------
<script>
var bFocus = false;
function keydown2(control)
{
var code = event.keyCode;
if(event.keyCode==13)
{
event.keyCode=9;
return true;
}
var the_obj = event.srcElement;
var the_td = get_Element(event.srcElement,"td");
if(the_td==null) return;
var the_tr = the_td.parentElement;
var the_table = get_Element(the_td,"table"); var cur_row = the_tr.rowIndex;
var cur_col = the_td.cellIndex;
if (code==38)
{
//alert("up");
cur_row = cur_row-1;
if (cur_row > -1)
{
var a = the_table.rows[cur_row].cells[cur_col].childNodes[0];
if (a.type=="text")
{
var r =a.createTextRange();
r.collapse();
r.select();
bFocus = true;
}
}
}
return true;
}function get_Element(the_ele,the_tag){
the_tag = the_tag.toLowerCase();
if(the_ele.tagName.toLowerCase()==the_tag)return the_ele;
while(the_ele=the_ele.offsetParent){
if(the_ele.tagName.toLowerCase()==the_tag)return the_ele;
}
return(null);
}</script>
<form method="post" action="abc.asp" name="form1">
<p> </p>
<p>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="1">
<TR>
<TD><input id="111" type="text" name="T11" onkeydown="return keydown2(this);" tblId="t01" onfocus="if(bFocus == true) {this.select();bFocus = false;}"></TD>
<TD><input id="222" type="text" name="T12" onkeydown="return keydown2(this);" tblId="t02"></TD>
</TR>
<TR>
<TD><input id="333" type="text" name="T13" onkeydown="return keydown2(this);" tblId="t11"></TD>
<TD>
<input id="444" type="text" name="T14" onkeydown="return keydown2(this);" tblId="t12">
</TD>
</TR>
</TABLE>
</p>
<p> </p>
<p>&
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript">
var cols=3;
var obj;
var CanMove=false;
var key;
function setobj(input){
obj=input;
} function init(){
document.onkeydown=keyDown;
document.onkeyup=keyUp;
} function keyDown(DnEvents){
var key=window.event.keyCode;
if(key==116){
window.event.keyCode=0;
return false;
}
if(key==8){
if(event.srcElement.tagName!="INPUT"){
event.cancelBubble = true;
event.returnValue = false;
return false;
}
}
var IsCtrl=window.event.ctrlKey;
if(!IsCtrl){
return;
}
for(var i=0;i<document.forms[0].elements.length;i++){
if(document.forms[0].elements[i]==obj){
if (key == 37){//←
if(i>0){
document.forms[0].elements[i-1].focus();
}
}
if (key == 38){//↑
if(i>cols-1){
document.forms[0].elements[i-cols].focus();
}
}
if (key == 39){//→
if(i<document.forms[0].elements.length-1){
document.forms[0].elements[i+1].focus();
}
}
if (key == 40){//↓
if(i<document.forms[0].elements.length-cols){
document.forms[0].elements[i+cols].focus();
}
}
}
} } function keyUp(UpEvents){
return false;
}
</script>
</head> <body bgcolor="#FFFFFF" text="#000000" onload="init()">
<form>
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<input type="text" name="textfield" onfocus="setobj(this);this.select()">
</td>
<td>
<input type="text" name="textfield2" onfocus="setobj(this);this.select()">
</td>
<td>
<input type="text" name="textfield3" onfocus="setobj(this);this.select()">
</td>
</tr>
<tr>
<td>
<input type="text" name="textfield5" onfocus="setobj(this);this.select()" value="灰豆宝宝.net">
</td>
<td>
<input type="text" name="textfield6" onfocus="setobj(this);this.select()" value="灰豆宝宝.net">
</td>
<td>
<input type="text" name="textfield7" onfocus="setobj(this);this.select()">
</td>
</tr>
</table>
</form>
用Ctrl+方向键可以方便的在控件中移动
</body>
</html>