简体   繁体   English

表单中的文本区域空白

[英]Text area white spaces in form

I have one form in with textarea: 我在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: 将计数限制为200的Javascript:

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? 但是,每当我打开表单时,都会得到多余的前导空格,并且显示的多余字符数超过200。如何在内容之前删除多余的空格?

删除源中<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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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