Check if the radio button is changed by the keyboard or mouse

后端 未结 6 1998
遇见更好的自我
遇见更好的自我 2021-01-15 08:14

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?

6条回答
  •  孤街浪徒
    2021-01-15 08:55

     
    
     $("#radiobtn").keyup(function(e) {
        var code = e.keyCode || e.which;
        if (code == 32) { 
           alert("Space bar was pressed");
        }
        else {
           alert("mouse click");
        }
     }); 
    

提交回复
热议问题