0
個々の文字の代わりにテキスト領域の単語を数えたいと思います。MVCの単語の制限
モデルクラス
[RegularExpression(@"[^<>]*", ErrorMessage = "Invalid entry"), StringLength(200)]
public string Day1Journal { get; set; }
HTML
@Html.TextAreaFor(m => m.StudentJournaldtls.Day1Journal, IsReadOnly == true || IsSubmitted == true ? (object)new { col = 2, @class = "CharacterLimit required", @maxlength = 200, @readonly = "readonly" } : new { col = 2, @class = "CharacterLimit required", @maxlength = 200 })
<small>No of characters left:<span class="charsLeft"></span></small>
Javascriptを
<script type="text/javascript">
$(function() {
$(".CharacterLimit").each(function (i, t) {
var charsLeft = $(this).attr("maxlength") - $(this).val().split(' ').length
$(this).parent().find(".charsLeft").text(charsLeft);
});
$(".CharacterLimit").keyup(function (e) {
var charsLeft = $(this).attr("maxlength") - $(this).val().split(' ').length
$(this).parent().find(".charsLeft").text(charsLeft);
});
</script>
こんにちは、私は言葉の数を得ることができました。しかし、単語の制限はまだ200文字で停止します。 – user3807187