Skip to content

Instantly share code, notes, and snippets.

@helloGoGo
Last active March 21, 2017 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helloGoGo/b1a762b865e8dabf6d4290e64dc84394 to your computer and use it in GitHub Desktop.
Save helloGoGo/b1a762b865e8dabf6d4290e64dc84394 to your computer and use it in GitHub Desktop.
入力値から前後の空白を削除してフィールドに再セット
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>trim</title>
<!--jQuery-->
<script src="../library/jquery/jquery-3.1.1.min.js"></script>
<script>
$(function(){
/**
* 入力値から前後の空白を削除してフィールドに再セット
*/
$('input').blur(function () {
var value = $(this).val();
$(this).val($.trim(value));
});
});
</script>
</head>
<body>
<input type="text" name="first_name"/>
<input type="text" name="last_name"/>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment