单击div时,事件处理程序将接收事件,因此您可以测试单击的位置.
如果需要的话,你可能想使用点击的元素的位置和大小,使用$(this).offset(),$(this).width()和$(this).height().例如 :
$('mydivselector').click(function(e) {
if (e.pageY > $(this).offset().top + 0.5*$(this).height()) {
// bottom was clicked
} else {
// up of the div was clicked
}
});
Run Code Online (Sandbox Code Playgroud)
如果要阻止默认操作和事件传播,请从事件处理程序返回false.