示例
描述:
Display a paragraph's text in an alert when it is clicked:
$("p").on("click", function(){
alert( $(this).text() );
});
Pass data to the event handler, which is specified here by name:
function myHandler(event) {
alert(event.data.foo);
}
$("p").on("click", {foo: "bar"}, myHandler)
Cancel a form submit action and prevent the event from bubbling up by returning false:
$("form").on("submit", false)
Cancel only the default action by using .preventDefault().
$("form").on("submit", function(event) {
event.preventDefault();
});
Stop submit events from bubbling without preventing form submit, using .stopPropagation().
$("form").on("submit", function(event) {
event.stopPropagation();
});