js中有能通过焦点得到元素的方法吗? 如题,比如当前焦点在一个textfield的上面,我能否得到这个元素的信息如id请写出代码 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 获得焦点时触发事件传入参数为当前元素。<html><head><script type="text/javascript"> function findIt(obj) { alert(obj.id + ' : ' + obj.name); }</script></head><body> <input type="text" id="sun" name="nus" onfocus="findIt(this);" /></body></html> <!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=utf-8" /><title>无标题文档</title><script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script><script>$(function(){ var idname= $(".a").attr("id"); alert(idname); })</script></head><body><input id = "我是ID" class="a" name="11" type="text" /></body></html> 不知道楼主是不是这个意思?确定是确定是获得焦点,不是onmouseover? var actId = document.activeElement.id;actId 就是当前获得焦点元素的ID 完全可以啊 ‘getAttribute("id");//js的方法或者JQUERY$("input").focus(function(){ $(this).attr("id");}); 如何在flash中定义自己的右键事件 select jquery 怎样改变文本节点的内容? 如何在CSS中设置图片的ALT Ext.MessageBox.alert同时只能弹出一个吗 jquery easyui-datebox渲染问题 js时间控件问题求助!!! 标签div中的内容如何动态改变 一个不知道可否解决的问题 请问如何用javascript控制<embed>里插入的音乐? Jquery的validate验证 ownerCt为空或不是对象
<html>
<head>
<script type="text/javascript">
function findIt(obj) {
alert(obj.id + ' : ' + obj.name);
}
</script>
</head>
<body>
<input type="text" id="sun" name="nus" onfocus="findIt(this);" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script>
$(function(){
var idname= $(".a").attr("id");
alert(idname);
})
</script>
</head><body>
<input id = "我是ID" class="a" name="11" type="text" /></body>
</html>
getAttribute("id");//js的方法
或者JQUERY
$("input").focus(function(){
$(this).attr("id");
});