日期:2014-05-19  浏览次数:20416 次

|M| 网页选择项目,如何在点击的时候给当前光标停留的地方赋值
如网页有控件
1   2   3   4   5   6   7   8   9   0

然后有两个文本框
T1     T2
当我的鼠票在T1时   点击控件1就把1赋值给T1
当我的鼠票在T2时   点击控件1就把1赋值给T2

谢谢

------解决方案--------------------
说得不是很清楚,鼠标在t2文本框时,怎么能点到控件1??
有两鼠标?
------解决方案--------------------
你点击 你的控件1的时候 实际上 焦点已经从t1移到了控件1上

网页是按焦点的来算当前操作的控件的
楼主要实现你的功能 应该用一个 隐藏框 在焦点到t1时候保存 id为t1
点击你的控件1时候 根据这个隐藏框来 赋值给t1或t2
------解决方案--------------------
在javascript中声明一个全局变量selID,T1和T2的onfocus中记录下选中的ID,在0~9的onclick中取值赋给selID记录的变量。
------解决方案--------------------
this.L1.Attributes.Add( "onmouseover ", "if(document.all.T1.focus){document.all.T1.value= '1 '}; ");
this.L1.Attributes.Add( "onmouseout ", "document.all.T1.value= ' ';document.all.T2.value= ' ' ");

------解决方案--------------------
<!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=gb2312 " />
<title> Test </title>
<script language= "javascript ">
var focusText;
function textOnFocus(id)
{
focusText=id;
}
function btClick(str)
{
if(focusText!=null)
{
document.getElementById(focusText).value=str;
}
}

</script>
</head> <p>
<input name= "bt1 " type= "button " value= "1 " id= "bt1 " onclick= "btClick(this.value); "/>
<input name= "bt2 " type= "button " value= "2 " id= "bt2 " onclick= "btClick(this.value); "/>
<input name= "bt3 " type= "button " value= "3 " id= "bt3 " onclick= "btClick(this.value); "/>
<input name= "bt4 " type= "button " value= "4 " id= "bt4 " onclick= "btClick(this.value); "/>
<input name= "bt5 " type= "button " value= "5 " id= "bt5 " onclick= "btClick(this.value); "/>
<input name= "bt6 " type= "button " value= "6 " id= "bt6 " onclick= "btClick(this.value); "/>
<input name= "bt7 " type= "button " value= "7 " id= "bt7 " onclick= "btClick(this.value); "/>
<input name= "bt8 " type= "button " value= "8 " id= "bt8 " onclick= "btClick(this.value); "/>
<input name= "bt9 " type= "button " value= "9 " id= "bt9 " onclick= "btClick(this.value); "/>
<input name= "bt0 " type= "button " value= "0 " id= "bt0 " onclick= "btClick(this.value); "/>

</p>
<p>

<input name= "t1 " id= "t1 " type= "text " onfocus= "textOnFocus(this.id); "/>
<input name= "t2 " id= "t2 " type= "text " onfocus= "textOnFocus(this.id); "/>
</p>

<body>