函數綁定到許多對象的事件。其中一個對象觸發事件,並且jQuery啓動。如何找出是誰在JavaScript函數中觸發了事件?使用jQuery獲取有關事件源的信息
我試過使用function [name](event){}
並戳事件,但我得到「'數據'爲空或不是對象」。
這裏是我的代碼現在:
<script type="text/javascript">
$(document).ready(function() {
$('.opening').bind("click", function(event) {
//code to populate event.data since right now, the tags don't hold the info...they will eventually with an XHTML custom namespace
event.data.building = "Student Center";
event.data.room = "Pacific Ballroom A";
event.data.s_time = "9/15/2009 8:00";
event.data.e_time = "9/15/2009 10:00";
indicatePreferenceByClick(event);
});
function indicatePreferenceByClick(event) {
alert("I got clicked and all I got was this alert box.");
$("#left").load("../ReserveSpace/PreferenceByClick", { building: event.data.building, room: event.data.room, s_time: event.data.s_time, e_time: event.data.e_time});
};
</script>
[獲取該燒製使用JQuery事件的元素的ID(可能的重複http://stackoverflow.com/questions/48239/getting-the-id-of-the-element-that-燒製的事件 - 使用 - jQuery的) – 2012-05-04 05:14:18