Create a gist now

Instantly share code, notes, and snippets.

@helloGoGo /trim.html
Last active Mar 21, 2017

What would you like to do?
入力値から前後の空白を削除してフィールドに再セット
<!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