2011-05-07 23 views

回答

1

使用originating elementnodeName属性,看看那里的事件起源:

$('#myDiv').click(function(event) { 
    if (event.target.nodeName.toLowerCase() === 'input') { 
     return; // ignore the event if it originated on an input element 
    } 

    // do the rest of your code 
}); 

如果你想要一个更复杂的查询(例如使用jQuery pseudoselectors),你可以使用is

$('#myDiv').click(function(event) { 
    if ($(event.target).is('input[name="foo"]')) { 
     return; // ignore the event if it originated on an input element with the name foo 
    } 

    // do the rest of your code 
}); 
+0

谢谢@lonesomeday,它的工作原理。 :) – 2011-05-07 15:35:58