根据W3C,该onclick
事件是由键盘出于可访问性目的触发的:
为了给不使用鼠标的用户提供更好的用户体验,已经开发了浏览器来触发onclick
事件,即使使用键盘进行 单击 也是如此。
因此,click
即使使用键盘的空格键单击了复选框,jQuery的事件也会触发。change
,显然,每次复选框状态更改时都会触发。
复选框恰好是change
且click
可互换的特殊情况,因为您不能在change
没有触发的情况下触发事件click
。
当然,此规则的例外情况是您是否要使用javascript手动更改复选框,例如:
/* this would check the check@R_900_2419@ without firing either 'change' or 'click' */
$('#someCheck@R_900_2419@').prop('checked',true);
/* this would fire 'change', but not 'click'. Note, however, that this
does not change the check@R_900_2419@, as 'change()' is only the function that
is fired when the check@R_900_2419@ changes, it is not the function that
does the changing */
$('#someCheck@R_900_2419@').trigger('change');
/* this would fire 'click', which by default change state of check@R_900_2419@ and automatically triggers 'change' */
$('#someCheck@R_900_2419@').trigger('click');
希望这可以帮助。