如何识别是否通过鼠标或键盘选中了复选框?

时间:2022-06-01 08:45:35

I know it's a weird question, but is possible to determinate (using PHP/JavaScrip) the device's source of the 'check action'? I need to find out when a user click on a checkbox option, which device he/she used to do the actual click.

我知道这是一个奇怪的问题,但是可以确定(使用PHP / JavaScrip)设备的“检查操作”来源吗?我需要找出用户何时单击复选框选项,他/她用来执行实际点击的设备。

I hope I made sense here.

我希望我在这里有道理。

1 个解决方案

#1


2  

With Javascript, this is easy. You can attach click and keydown events to the checkbox (onclick, onkeydown, or use jQuery if you want) and they will be triggered on click or keydown. By "click" with the keyboard I assume you mean highlighting the checkbox via tabbing and pressing space. This will still trigger the keydown event, but not the click.

使用Javascript,这很容易。您可以将click和keydown事件附加到复选框(onclick,onkeydown,或者如果需要,可以使用jQuery),它们将在click或keydown时触发。通过键盘“点击”我假设您的意思是通过Tab键和按空格突出显示复选框。这仍然会触发keydown事件,但不会触发点击。

#1


2  

With Javascript, this is easy. You can attach click and keydown events to the checkbox (onclick, onkeydown, or use jQuery if you want) and they will be triggered on click or keydown. By "click" with the keyboard I assume you mean highlighting the checkbox via tabbing and pressing space. This will still trigger the keydown event, but not the click.

使用Javascript,这很容易。您可以将click和keydown事件附加到复选框(onclick,onkeydown,或者如果需要,可以使用jQuery),它们将在click或keydown时触发。通过键盘“点击”我假设您的意思是通过Tab键和按空格突出显示复选框。这仍然会触发keydown事件,但不会触发点击。