jQuery textarea text box input text word limit prompt code
<script type="text/javascript"> //Display restricted input characters method function textAreaChange(obj){ var $this = $(obj); var count_total = $this.next().children('span').text(); var count_input = $this.next().children('em'); var area_val = $this.val(); if(area_val.len()>count_total){ area_val = autoAddEllipsis(area_val,count_total); //According to the byte screenshot content $this.val(area_val); count_input.text(0);//Display the number that can be entered }else{ count_input.text(count_total - area_val.len());//Display the number that can be entered } } //Get the byte length of the string String.prototype.len = function(){ return this.replace(/[^\x00-\xff]/g, "xx").length; }; /* * Process too long strings, intercept and add ellipses * Note: The half-width length is 1 and the full-width length is 2 * pStr: string * pLen: intercept length * return: intercepted string */ function autoAddEllipsis(pStr, pLen) { var _ret = cutString(pStr, pLen); var _cutFlag = _ret.cutflag; var _cutStringn = _ret.cutstring; return _cutStringn; } /* * Get a string of specified length * Note: The half-width length is 1 and the full-width length is 2 * pStr: string * pLen: intercept length * return: intercepted string */ function cutString(pStr, pLen) { // Original string length var _strLen = pStr.length; var _tmpCode; var _cutString; // By default, the returned string is part of the original string var _cutFlag = "1"; var_lenCount = 0; var _ret = false; if (_strLen <= pLen/2){_cutString = pStr;_ret = true;} if (!_ret){ for (var i = 0; i < _strLen ; i++ ){ if (isFull(pStr.charAt(i))){_lenCount += 2;} else {_lenCount += 1;} if (_lenCount > pLen){_cutString = pStr.substring(0, i);_ret = true;break;} else if(_lenCount == pLen){_cutString = pStr.substring(0, i + 1);_ret = true;break;} } } if (!_ret){_cutString = pStr;_ret = true;} if (_cutString.length == _strLen){_cutFlag = "0";} return {"cutstring":_cutString, "cutflag":_cutFlag}; } /* * Determine whether it is full-width * * pChar: a string of length 1 * return: true: full width * false: half-width */ function isFull (pChar){ if((pChar.charCodeAt(0) > 128)){return true;} else{return false;} } </script>
jQuery textarea text area text box input word limit prompt code, set fixed input characters, real-time calculation and display of how many characters have been entered.
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article
26 Apr 2023
In front-end development, we often need to use jQuery to handle some interactive effects and animation effects, such as animation effects when the mouse is hovering, animation effects when the page is loading, etc. But sometimes we need to set a delay time so that these effects can be better expressed. So, how does jQuery set a delay? This article will introduce this issue in detail. 1. Delay method in jQuery In jQuery, delay effect can be easily achieved by using the delay() method. The delay() method can be used
16 May 2016
jQuery UI CSS Framework is a style framework in jQuery UI. You can use jQuery Theme roller to generate the css style effects you want. We can use some frameworks of jQuery UI to develop plug-ins based on jQuery UI CSS Framework effects.
16 May 2016
animate() is a method in jquery that can be used to create animation effects. The animate() method in jquery adds good visual effects to that page.
23 May 2023
With the popularity of the Internet, the application of typing effects is becoming more and more widespread, and jquery typing effects have become the first choice of many website developers. However, in the process of realizing this special effect, detailed issues often affect the user experience, such as the problem of deletion of typing special effects. This article will introduce how to use jquery typing effects to stop deletion and improve the user's browsing experience. The implementation of jquery typing effects can use ready-made plug-ins, such as typed.js and jQuery.Typewriter. These plug-ins are based on jquery
16 May 2016
This article collects three different types of jquery timeline effects for everyone, involving jquer related knowledge. Friends who are interested in jquery timeline effects can refer to this article.
28 Nov 2018
Animation effects in jQuery include: slideDown, slideUp, etc. to achieve sliding effects; fadeIn, fadeToggle, etc. to achieve fade-in and fade-out effects.
16 May 2016
There are many jquery prompt effects. This article also provides a super beautiful pop-up layer effect imitating Tencent. If you love special effects, don’t miss it. I hope the cases provided in this article will be helpful for you to learn jquery special effects.
28 May 2023
jQuery is a powerful JavaScript library that greatly simplifies the work of developers and designers. Among them, Jquery’s animation effect has become one of the most important elements in design. This article will introduce how to use jQuery to create animation effects. 1. jQuery animation effects jQuery animation effects are generally implemented using the animate() function. It allows programmers to create transition animations on one or more CSS properties. animate() function requires
16 May 2016
This article mainly introduces jQuery animation special effects, and describes in detail the implementation method of jQuery animation special effects. It is very practical. Friends who need it can refer to it.
Hot Tools
jQuery2019 Valentine's Day Confession Fireworks Animation Special Effects
A very popular jQuery Valentine's Day confession fireworks animation special effect on Douyin, suitable for programmers and technical geeks to express their love to the girl they love. No matter you choose to be willing or not, you have to agree in the end.
layui responsive animated login interface template
layui responsive animated login interface template
520 Valentine's Day confession web animation special effects
jQuery Valentine's Day Confession Animation, 520 Confession Background Animation
Cool system login page
Cool system login page
HTML5 tape music player-CASSETTE PLAYER
HTML5 tape music player-CASSETTE PLAYER