Last active
March 10, 2020 10:11
-
-
Save trmtsy/5692261 to your computer and use it in GitHub Desktop.
テキストボックスでエンターが押された時に実行されるJavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | |
<title>keypress</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
</head> | |
<body id="content"> | |
<input id="textInput" type="text"> | |
<div id="textOut"></div> | |
<script type="text/javascript" charset="utf-8"> | |
// テキストエリアでENTERが押された時のイベント | |
$('#textInput').keypress(function(e) { | |
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { | |
console.log('which:' + e.which); | |
console.log('keyCode:' + e.keyCode); | |
$('#textOut').text($('#textInput').val()); | |
$('#textInput').val(''); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment