jQueryを使用して、入力が指定された制限より短い場合にアラートメッセージを表示しようとしています。残念ながら、私のコードは機能していないので、あなたの助けを求めています。
これが私が使用しているコードです。
HTML
<input type="textarea" name="message" id="message" row="20" col="50" />
<input type="submit" name="submit" id="submit" value="Send Message" />
JavaScript
<script type="text/javascript">
jQuery(document).ready(function($) {
$("input:submit[name='submit']").on("click",function() {
var msgwords = $("input:textarea[name='message']").val().replace( /[^\w ]/g, "" ).split( /\s+/ ).length;
var minwords = 10;
if (comwords < minwords) {
alert("Your Comment is too short.");
}
});
});
</script>