日期:2014-05-16  浏览次数:20360 次

jQuery获取当前点击对象
如何获取,是用jQuery,而不是event.scrElement

因为$(event.scrElement)无法将其转换为jq对象,不知道是什么原因

------解决方案--------------------
HTML code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 <script type="text/javascript" src="jquery-1.2.1.js"></script>
 <script type="text/javascript">
    $(document).ready(function(){
        $(":input").click(function(){
            alert($(this).attr("name"));
        })
    });
 </script>

 </HEAD>

 <BODY>
    <input type="button" name="test1" value="test1">
    <input type="button" name="test2" value="test2">
    <input type="button" name="test3" value="test3">
    <input type="button" name="test4" value="test4">
    <input type="button" name="test5" value="test5">
    <input type="button" name="test6" value="test6">
 </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>
<title>无标题页</title>

<script src="../脚本/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("#Button1").bind("click",function(){
//this就是当前点击的对象
alert($(this).attr("name"));
})
})
</script>
</head>
<body>
<input id="Button1" name="ws_hgo" type="button" value="button" />
</body>
</html>