$(function(){ checkInput(); checkTextarea(); }); function checkInput() { $("input").keydown(function () { var length = $(this).val().length; var max = $(this).attr("maxlength"); var readOnly = $(this).attr("readonly"); var id = $(this).attr("id"); var num = max - length; $("#p_" + id).remove(); if (!readOnly) { if (num > 0) { $(this).after("<p id=p_" + id + "><span style=color:blue>剩余字符数:<span style=color:#00ff00>" + num + "</span></span></p>"); } } }); } function checkTextarea() { $("textarea").keydown(function () { var length = $(this).val().length; var max = $(this).attr("maxlength"); var readOnly = $(this).attr("readonly"); var id = $(this).attr("id"); var num = max - length; $("#p_" + id).remove(); if (!readOnly) { if (num > 0) { $(this).after("<p id=p_" + id + "><span style=color:blue>剩余字符数:<span style=color:#00ff00>" + num + "</span></span></p>"); } } }); }
input\textarea剩余字符数提示(jQuery)
最新推荐文章于 2024-06-18 23:00:00 发布