js和jquery如何实现input text键盘回车事件监测?
网友回复
首先jquery方式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" /> <title>BFW NEW PAGE</title> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery.17.js"></script> <script type="text/javascript"> $(function() { $(".input-cname").keypress(function (e) { if (e.which == 13) { alert("1"); } }); }); </script> <style> </style> </head> <body> <input class="input-cname" /> </body> </html>原生js方式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <script type="text/javascript"> function CheckInfo(event) { if (event.keyCode == 13) { alert( document.getElementById("textbox1").value); } } </script> <input type="text" id="textbox1"BfwOnkeypress="CheckInfo(event)" /> </body> </html>