简体   繁体   中英

Text area white spaces in form

I have one form in with textarea:

<textarea wrap="physical" cols="28" rows="5" name="<portlet:namespace />tsSummary" onKeyDown="CountRight(this.form.<portlet:namespace />tsSummary,this.form.right,200);getElementById('char_count_summary').innerHTML = this.value.length" onKeyUp="CountRight(this.form.<portlet:namespace />tsSummary,this.form.right,200);getElementById('char_count_summary').innerHTML = this.value.length" onfocus="getElementById('char_count_summary').innerHTML = this.value.length">
                    <c:choose><c:when test="<%=Validator.isNotNull(dMang)%>"><%=dMang.getTsSummary()%></c:when><c:otherwise><%=""%></c:otherwise></c:choose>
            </textarea>
                <b><span id=char_count_summary></span></b>
                <input readonly type="hidden" name="right" size=3 maxlength=3>

Javascript for limiting count to 200:

function CountRight(field, count, max) {
        // if the length of the string in the input field is greater than the max value, trim it
        if (field.value.length > max)
        field.value = field.value.substring(0, max);
        else
        // calculate the remaining characters
        count.value = max - field.value.length;
    }

But, I get extra leading white spaces whenever i open the form and it takes extra characters showing count more than 200. How can I remove extra blank spaces before content?

删除源中<textarea …><c:choose>之间的空格

function trim(value) {
  value = value.replace(/^\s+/,''); 
  value = value.replace(/\s+$/,'');
  return value;
}

this removes any whitespace on the start or end of a string. You could do something like

field.value = trim(field.value);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM