onFocus事件

jiffy1985 2009-07-17 05:01:51
下面的onFocus事件无效,如何在JS正确编写onFocus事件?


<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>

</head>

<body>
<a id="test">aaa</a>
<script type="text/javascript">
var a=document.getElementById("test");
a.onFocus=function (){
alert("");
}
</script>
</body>
</html>
...全文
392 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
benjaminwu198818 2009-07-18
  • 打赏
  • 举报
回复
还是老版的好 ,户户…
jamesmos 2009-07-18
  • 打赏
  • 举报
回复
onfocus是小写。

界面太难看了。
helanye 2009-07-17
  • 打赏
  • 举报
回复
事件名字写错了.
chen_ya_ping 2009-07-17
  • 打赏
  • 举报
回复
onfocus不是你那个onFocus
浪尖赏花 2009-07-17
  • 打赏
  • 举报
回复
严重同意,界面又丑,又卡
浪尖赏花 2009-07-17
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zetifree 的回复:]
不是吧,w3cshcool上明显写着, <a>标签是有onfocus事件属性的
见这里
[/Quote]
首先,onFocus的f小写onfocus
然后,a标签要触发focus事件,必须要有连接
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>

</head>

<body>
<a id="test" href="javascript:;">aaa</a>
<script type="text/javascript">
var a=document.getElementById("test");
a.onfocus=function (){
alert("focus");
}
</script>
</body>
</html>
浪尖赏花 2009-07-17
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zetifree 的回复:]
不是吧,w3cshcool上明显写着, <a>标签是有onfocus事件属性的
见这里
[/Quote]
首先,onFocus的f小写onfocus
然后,a标签要触发focus事件,必须要有连接
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>

</head>

<body>
<a id="test" href="javascript:;">aaa</a>
<script type="text/javascript">
var a=document.getElementById("test");
a.onfocus=function (){
alert("focus");
}
</script>
</body>
</html>
wtcsy 2009-07-17
  • 打赏
  • 举报
回复
恩 a 加个href 的属性就好了!~
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>

</head>

<body>
<a href="#" id="test">aaa</a>
<input id='ss' type="text" />
<script type="text/javascript">
window.onload = function(){
var a=document.getElementById("test");
var sss=document.getElementById("ss");
a.onfocus=function (){
alert("");
}
sss.onfocus=function (){
alert("");
}
}
</script>
</body>
</html>

zetifree 2009-07-17
  • 打赏
  • 举报
回复
不是吧,w3cshcool上明显写着,<a>标签是有onfocus事件属性的
见这里
wtcsy 2009-07-17
  • 打赏
  • 举报
回复
应该是a标签没获取焦点这个事件吧
同样的代码 input就可以
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>

</head>

<body>
<a id="test">aaa</a>
<input id='ss' type="text" />
<script type="text/javascript">
window.onload = function(){
var a=document.getElementById("test");
var sss=document.getElementById("ss");
a.onfocus=function (){
alert("");
}
sss.onfocus=function (){
alert("");
}
}
</script>
</body>
</html>




















cddn的界面换的真难看!!!!!!!!!!
wtcsy 2009-07-17
  • 打赏
  • 举报
回复
应该是a标签没获取焦点这个事件吧
同样的代码 input就可以
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>

</head>

<body>
<a id="test">aaa</a>
<input id='ss' type="text" />
<script type="text/javascript">
window.onload = function(){
var a=document.getElementById("test");
var sss=document.getElementById("ss");
a.onfocus=function (){
alert("");
}
sss.onfocus=function (){
alert("");
}
}
</script>
</body>
</html>




















cddn的界面换的真难看!!!!!!!!!!

87,901

社区成员

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

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