<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>event.which demo</title> <script src="https://code.jquery.com/jquery-1.10.2.js"></script></head><body><input id="whichkey" value="type something"><div id="log"></div><script>$( "#whichkey" ).on( "keydown", function( event ) { $( "#log" ).html( event.type + ": " + event.which );});</script></body></html>
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>event.which demo</title> <script src="https://code.jquery.com/jquery-1.10.2.js"></script></head><body><input id="whichkey" value="click here"><div id="log"></div><script>$( "#whichkey" ).on( "mousedown", function( event ) { $( "#log" ).html( event.type + ": " + event.which );});</script></body></html>
本文提供了两个使用event.which属性的示例,展示了如何在键盘按键和鼠标点击事件中捕获并显示事件类型及其对应的数值。示例使用了jQuery库简化事件监听器的设置。
790

被折叠的 条评论
为什么被折叠?



