Is there any way to get the ID of the element that fires an event?
(有什么方法可以获取触发事件的元素的ID?)
I'm thinking something like:
(我在想类似的东西:)
<html>
<head>
<script type="text/javascript" src="starterkit/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("a").click(function () {
var test = caller.id;
alert(test.val());
});
});
</script>
</head>
<body>
<form class="item" id="aaa">
<input class="title"></input>
</form>
<form class="item" id="bbb">
<input class="title"></input>
</form>
</body>
</html>
Except of course that the var test
should contain the id "aaa"
, if the event is fired from the first form, and "bbb"
, if the event is fired from the second form.
(当然,如果从第一种形式触发事件,则var test
应包含id "aaa"
;如果从第二种形式触发事件,则应包含id "bbb"
。)
ask by Joda translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…