如何得到焦点所在对象的类型呢?

51946486 2002-11-18 01:50:22
就是说一个焦点移到一个控件上,比如RADIOBUTTON我想让程序知道他是RADIOBUTTON并将焦点自动移到下一个控件上。
...全文
22 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
seabell 2002-11-19
  • 打赏
  • 举报
回复
<script>
function init(form)
{
for(var m=0;m<myform.elements.length;m++){
var ob=myform.elements[m];
ob.onkeydown=new Function("checkkey(this)");
if(ob.type=="radio"){
ob.onfocus=new Function("nextfocus(this)");
}
}
}

function checkkey(obj)
{
if(event.keyCode==13)
nextfocus(obj);
}

function nextfocus(obj)
{
document.all(obj.sourceIndex+1).focus();
}
</script>
<body onload=init()>
<form name=myform>
<input type=text id=mytext>
<input type=text id=mytext2>
<input type=checkbox id=mycheck>
<input type=radio name=myradio checked value=1>text
<input type=radio name=myradio value=2>checkbox
<input type=radio name=myradio value=3>select
<input type=text id=mytext3>
<select id=mysel>
<option>1
<option>2
</select>
</form>
51946486 2002-11-19
  • 打赏
  • 举报
回复
谢谢大家的捧场了,我的意思是说一排html控件其中有radiobutton控件,按回车键后焦点从一个控件上移倒下一个控件,但如果下一个控件是radiobutton的话,焦点会自动跳过这个控件而移到它的下面那个控件上。弄了半天没弄出来,请大家执教.
doli 2002-11-18
  • 打赏
  • 举报
回复
function init()
{
e = event.srcElement;
if(e.type=="RADIO")
{
e.focus();
}
}

bencalie 2002-11-18
  • 打赏
  • 举报
回复
W3 DOM

objectID.nextSibling.focus()
seabell 2002-11-18
  • 打赏
  • 举报
回复
<script>
function init(form)
{
for(var m=0;m<myform.elements.length;m++){
var ob=myform.elements[m];
if(ob.type=="radio"){
ob.onfocus=new Function("nextfocus(this)");
}
}
}

function nextfocus(obj)
{
document.all(obj.sourceIndex+1).focus();
}
</script>
<body onload=init()>
<form name=myform>
<input type=checkbox id=mycheck>
<input type=radio name=myradio checked value=1>text
<input type=radio name=myradio value=2>checkbox
<input type=radio name=myradio value=3>select
<input type=text id=mytext>
<select id=mysel>
<option>1
<option>2
</select>
</form>

87,909

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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