检查单选按钮是否被键盘或鼠标更改 [英] Check if the radio button is changed by the keyboard or mouse
本文介绍了检查单选按钮是否被键盘或鼠标更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以说出如何选择单选按钮,即用户是使用键盘还是鼠标单击单选按钮?
Is possible to tell how a radio button was selected, i.e. if the user used the keyboard or the mouse to click the radio button?
推荐答案
似乎不能与更改事件一起使用. 我以这种方式解决,如果有人知道更优雅的方式,请告诉我:
Seems that is not doable with a change event. I resolved in this way, If someone knows a more elegant way let me know:
<input name="text" type="input">
<input name="radioButton" type="radio" value="1"> 1
<input name="radioButton" type="radio" value="2"> 2
<input name="radioButton" type="radio" value="3"> 3
var radioButtonValue;
$('input[name="radioButton"]').on("click", function(e) {
var value = $(this).val();
if (value !== radioButtonValue) {
if (e.clientX === 0 && e.clientY === 0) {
console.log("keyboard");
} else {
console.log("mouse");
};
radioButtonValue = value;
}
});
http://jsfiddle.net/gy59n3u6/1/
这篇关于检查单选按钮是否被键盘或鼠标更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文