PrimeFaces inputTextarea counterTemplate 中使用的字符数和总字符数 [英] Used and total character count in PrimeFaces inputTextarea counterTemplate

查看:31
本文介绍了PrimeFaces inputTextarea counterTemplate 中使用的字符数和总字符数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于素面的问题.我有一个文本框,我需要该文本框内的字符限制以及给出当前字符状态的输出文本.

I have a question regarding primefaces. I have a textbox and I needed a character limit within that textbox as well as output text giving the current character status.

目前,我的计数器看起来像这样:

Currently, my counter looks like this:

比起字符计数向下,我更喜欢计数向上.更像是使用了 32/50 个字符".

Rather than a character countdown, I would prefer a countup. Something more like "32/50 characters used".

这是我做的代码:

<p:inputTextarea id="recommendedToolsOther" rows="4"
    style="vertical-align: top; width: 98% !important;" styleClass="preformatted"
    autoResize="false" value="#{rfeBean.rfe.otherRecommendedTools}"
    disabled="#{!rfeBean.recommendedToolsChecked[ReferralTemplateConstants.RECOMMENDED_TOOLS_HAND_OTHER]}"
    counter="displayRecTools" maxlength="50"
    counterTemplate="{0} characters remaining">
    <p:ajax event="change" update="recommendedToolsOther"/>
</p:inputTextarea>
<br/>
<h:outputText id="displayRecTools" />

我知道如何做到这一点.表示剩余字符数的变量用R表示.使用的字符数用U表示.
我需要这样做:U = (C-50)*(-1)

I have an idea of how I can do this. The variable that represents the number of characters remaining is represented by R. The amount of characters used is represented by U.
I would need to do this: U = (C-50)*(-1)

我只是不知道如何在素数面上做这样的代数.

I'm just not sure how to do algebra like that on primefaces.

推荐答案

我认为 PF 计数器不可能...如果你想回到 jQuery 这对我有用:

I don't think its possible with the PF counter... if you wanna fall back to jQuery this works for me:

<p:inputTextarea id="textarea" maxlength="20" onfocus="updateCount()" onkeyup="updateCount()"/>
<div id="counter"/>

<script>
    function updateCount() {
        $("[id$='counter']").html($("[id$='textarea']").val().length + "/" + $("[id$='textarea']").attr('maxlength') + " characters used");
    }
</script>

这篇关于PrimeFaces inputTextarea counterTemplate 中使用的字符数和总字符数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆