jQuery dynamically calculates the number of inputable words in a text box

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery dynamically calculates the number of input characters in the text box</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/textSum.min.js"></script>
<style type="text/css">
*{ box-sizing:border-box;}
body{ background:#f4f4f4;}
span{ font-size:12px;}
p{ margin:5px 0;}
.textWrap{ margin:10px 0 20px;}
.textWrap input,.textWrap textarea{ display:inline-block; background:#fff; border-radius:4px; border:1px solid #ddd; height:34px; width:100%; padding:7px 12px; padding-right:80px; line-height:20px; font-size:14px; color:#333;}
.textWrap textarea{ height:80px;}
</style>
</head>

<body>
<br>
<div style="margin:50px auto; width:60%;">
	<p><span>input maxlength = 10</span></p>
    <div class="textWrap wordSumTotal">
    	<input type="text" name="" maxlength="10">
    </div>
	<p><span>input maxlength = 20</span></p>
    <div class="textWrap wordSumTotal">
    	<input type="text" name="" style="height:46px;" maxlength="20">
    </div>
	<p><span>input maxlength By default, the default maxlength = 10</span></p>
    <div class="textWrap wordSumTotal">
    	<input type="text" name="">
    </div>
    
	<p><span>textarea maxlength = 20</span></p>
    <div class="textWrap wordSumTotal">
    	<textarea name="" cols="" rows="" maxlength="200"></textarea>
    </div>
    <br>
    <p>How to use:</p>
    <p><pre><code>$('class or element').textSum();</code></pre></p>
</div>

<script type="text/javascript">
$(function(){
	$('.wordSumTotal').textSum();
});
</script>
</body>
</html>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326440842&siteId=291194637