Skip to content

Instantly share code, notes, and snippets.

@masahiro-yoshitachi
Last active December 1, 2016 00:44
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 masahiro-yoshitachi/392a19d03b5dd10edd6d283acc516e51 to your computer and use it in GitHub Desktop.
Save masahiro-yoshitachi/392a19d03b5dd10edd6d283acc516e51 to your computer and use it in GitHub Desktop.
jQueryで現在の文字数を動的に表示させる
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script>
$(function(){
$("#message").bind("change keyup",function(){
var count = $(this).val().length;
$("#num").text("【現在の文字数】"+count);
if( count > 0 ){
$("input:submit").attr('disabled', false);
}else{
$("input:submit").attr('disabled', true);
}
});
$("form").submit(function(e){
alert("submit!!");
});
});
</script>
<title>jQueryサンプルコード</title>
</head>
<body>
<form name="frm_test" method="post" action="">
<div id="c_waku"><p id="num">【現在の文字数】0</p>
<textarea id="message" rows="10" cols="50"></textarea>
</div>
<input type="submit" name="frm_sub" value="送信" disabled>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment