mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Fix #10701, .preventDefault if an inline handler returns false.
Baby unicorns are slapped each time you use inline handlers, so do it sparingly.
This commit is contained in:
parent
1e677f30f6
commit
90c907e8b6
@ -343,9 +343,10 @@ jQuery.event = {
|
||||
if ( handle ) {
|
||||
handle.apply( cur, data );
|
||||
}
|
||||
// Note that this is a bare JS function and not a jQuery handler
|
||||
handle = ontype && cur[ ontype ];
|
||||
if ( handle && jQuery.acceptData( cur ) ) {
|
||||
handle.apply( cur, data );
|
||||
if ( handle && jQuery.acceptData( cur ) && handle.apply( cur, data ) === false ) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if ( event.isPropagationStopped() ) {
|
||||
|
@ -2273,6 +2273,18 @@ test("Non DOM element events", function() {
|
||||
jQuery(o).trigger("nonelementobj");
|
||||
});
|
||||
|
||||
test("inline handler returning false stops default", function() {
|
||||
expect(1);
|
||||
|
||||
var markup = jQuery('<div><a href="#" onclick="return false">x</a></div>');
|
||||
markup.click(function(e) {
|
||||
ok( e.isDefaultPrevented(), "inline handler prevented default");
|
||||
return false;
|
||||
});
|
||||
markup.find("a").click();
|
||||
markup.off("click");
|
||||
});
|
||||
|
||||
test("window resize", function() {
|
||||
expect(2);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user