|M| 网页选择项目,如何在点击的时候给当前光标停留的地方赋值

zyciis169 2007-03-25 09:46:55
如网页有控件
1 2 3 4 5 6 7 8 9 0

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

谢谢
...全文
168 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyciis169 2007-03-25
  • 打赏
  • 举报
回复
对也就是用多一个来记录上一个在什么地方

谢谢大家
hertcloud 2007-03-25
  • 打赏
  • 举报
回复
<!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>
<script type="text/javascript">
<!--
function focusID(_ID)
{
//安装楼主意思是鼠标悬停 应该是onmouseover 但是对于实际操作应该onfocus更适合
document.getElementById('curTID').value = _ID;
}
function setText(val)
{
var txtID = document.getElementById('curTID').value;
document.getElementById(txtID).value = val;
}
//-->
</script>
</head>

<body>
T1: <input type="text" id="t1" onmouseover="focusID(this.id);" /><br />
T2: <input type="text" id="t2" onmouseover="focusID(this.id);" /><input type="hidden" id="curTID" value="" /><br />
<input type="button" id="btn01" value="test1" onclick="setText(this.value);" /><br />
<input type="button" id="btn02" value="test2" onclick="setText(this.value);"/><br />
<input type="button" id="btn03" value="test3" onclick="setText(this.value);"/><br />
<input type="button" id="btn04" value="test4" onclick="setText(this.value);"/>......<br />
</body>
</html>
RunUpwind 2007-03-25
  • 打赏
  • 举报
回复
试一下,不知楼主是不是这个意思
RunUpwind 2007-03-25
  • 打赏
  • 举报
回复
<!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>
</body>
</html>
wangkun9999 2007-03-25
  • 打赏
  • 举报
回复
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=''");
最后一只恐龙 2007-03-25
  • 打赏
  • 举报
回复
在javascript中声明一个全局变量selID,T1和T2的onfocus中记录下选中的ID,在0~9的onclick中取值赋给selID记录的变量。
hertcloud 2007-03-25
  • 打赏
  • 举报
回复
你点击 你的控件1的时候 实际上 焦点已经从t1移到了控件1上

网页是按焦点的来算当前操作的控件的
楼主要实现你的功能 应该用一个 隐藏框 在焦点到t1时候保存 id为t1
点击你的控件1时候 根据这个隐藏框来 赋值给t1或t2
ice321105 2007-03-25
  • 打赏
  • 举报
回复
说得不是很清楚,鼠标在t2文本框时,怎么能点到控件1??
有两鼠标?

62,251

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧