例如回车事件(keyCode为13),选择器class为“search-term”,触发方法为searchTermInfo();
document.onkeydown = function (event)
{
var event = event || window.event;
var target = event.srcElement || event.target;
if (event.keyCode == 13 && target.getAttribute("class") == "search-term")
{
searchTermInfo();
}
}
不设定选择器,在窗口点击,返回的是event.which 值,即按键的keycode:
$(window).keydown( function(event){
$("body").append( "<br>你按下的按键的代码值为:[" + event.which + ‘]‘ ) ;
} );
时间: 2024-10-12 16:11:53