javascript - Word count jquery and stop user from typing -


  $ (दस्तावेज़) .ready (function () {$ ("input")। Keyup (फ़ंक्शन () {If ($ (this) .val ()। Split ('') .length == 10) {alert ()}}})}};  
  & lt; स्क्रिप्ट src =" https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js "& gt; & lt; / लिपि & gt; अपना नाम दर्ज करें: & lt; इनपुट प्रकार = "टेक्स्ट" & gt;  

यदि इनपुट 1 2 3 4 5 6 7 8 9 चेतावनी निकाल दिया, मुझे पता है कि यह अंतरिक्ष शामिल है लेकिन जब उपयोगकर्ता की सीमा तक पहुंचने पर अधिक चरित्र (यहां तक ​​कि अंतरिक्ष) जोड़ने से कैसे रोकें?

अधिकतम शब्द संख्या तक पहुँचने पर स्पेस बार अक्षम करने के लिए समस्या को आसानी से सरल किया जा सकता है:

यह काम करना चाहिए:

  & lt; इनपुट डेटा-अधिकतम-शब्द = "10" / & gt;  

जेएस:

  $ ('input [data-max-words]')। पर ('keydown', फ़ंक्शन (e) {var $ Txt = $ (this), अधिकतम = $ txt.data ('maxwords'), वैल = $ txt.val (), शब्द = val.split ('')। लांघ; अगर (शब्द === अधिकतम & amp; ; E.keycode === 32) वापसी झूठी;});  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -