微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

计算我的xp:inputText控件的字符数

如何解决计算我的xp:inputText控件的字符数

我将xp:inputText控件绑定到了一个观察镜。现在,我想在用户输入10个字符后从按钮上删除disable属性,但是onkeypress或onchange事件(服务器)似乎仅在我离开输入控件后才提交某些内容

如何解决此服务器端?

解决方法

如果确实要使用客户端解决方案,请将类似的内容放入页面或页面底部的自定义控件中。

<xp:scriptBlock>
setInterval(function () {
  if(XSP.getElementById("#{id:textInputFieldName}").val().length > 9) {
    XSP.getElementById("#{id:submitButtonName}").removeAttr("disabled");
  } else {
    XSP.getElementById("#{id:submitButtonName}").attr("disabled","disabled");
  }
},500); //Runs every 0.5s
</xp:scriptBlock>

这每500毫秒运行一次,并检查文本输入的长度是否大于9个字符。如果是,它将删除按钮的禁用属性,否则将保持该属性为开。即使人们将数据复制并粘贴到该字段中,该方法仍然有效,而使用按键的解决方案可能不会拾取粘贴事件。

您将需要更改元素的ID。

,

在服务器端,您应该使用onkeydown事件并从部分刷新中禁用按钮。

   <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-core</artifactId>
                <version>9.0.39</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

   <dependencies>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-core</artifactId>
        <version>9.0.39</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。