में शब्द गणना:jQuery: मैं निम्नलिखित jQuery कार्यक्षमता का उपयोग कर रहा वास्तविक समय में शब्दों की गिनती करने के वास्तविक समय
$("input[type='text']:not(:disabled)").each(function(){
var input = '#' + this.id;
word_count(input);
$(this).keyup(function(){
word_count(input);
})
});
var word_count = function(field) {
var number = 0;
var original_count = parseInt($('#finalcount').val());
var matches = $(field).val().match(/\b/g);
if(matches) {
number = matches.length/2;
}
$('#finalcount').val(original_count + number)
}
मुद्दा मैं में चल रहा है कि जब मैं एक इनपुट फ़ील्ड में टाइप करना आरंभ, गिनती रिक्त स्थान और मेरी हटाई कुंजी पर भी दो से तुरंत बढ़ता है। कोई विचार क्यों ऐसा होगा?
मैं इस ट्यूटोरियल पीछा कर रहा था: http://www.electrictoolbox.com/jquery-count-words-textarea-input/
इनपुट: <input class="widest" id="page_browser_title" name="page[browser_title]" size="30" type="text" value="">
प्रदर्शन इनपुट: <input class="widest" disabled="disabled" id="finalcount" name="page[word_count]" size="30" type="text" value="662">
आप इनपुट और प्रदर्शन div के लिए भी अपने html में प्रवेश कर सकते हैं? – willdanceforfun
क्या आपके पास [jsfiddle] (http://jsfiddle.net) है? –
यहां jsfiddle का एक लिंक है ... http://jsfiddle.net/M7Jny/ – dennismonsewicz