文字区域html控件 [英] Text Area html Control

查看:54
本文介绍了文字区域html控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有textArea htmlControl,我已将其最大宪章数设置为150.
我需要一个动态文本计数器,当我在其中键入文本时,该计数器会减少文本计数.

I have textArea htmlControl for which i have set Maximum charter count to 150.
I need a dynamic text counter that will decrement the text count as i type text in it.

any link?

推荐答案

This[^] could probably help you get started and create what you want.


看起来像您在寻找这些东西:
JavaScript动态文本区域计数器 [检查TextArea长度 [更多 [
Looks like you are looking for these:
Javascript Dynamic Text Area Counter[^]
Check TextArea Length[^]

If needed, look here for more[^].


这是完整的示例:

This is a full sample:

<html>
   <head>
      <script type="text/javascript"><!--
         function counter(eventInstance, max) {
            eventInstance = eventInstance || window.event;
            key = eventInstance.keyCode || eventInstance.which;
            tarea = document.getElementById("tarea");
            output = document.getElementById("output");
            allowed = max-tarea.value.length;
            output.innerHTML = allowed + " remainin";
            if (allowed <= 0 & key != 8) {
               eventInstance.preventDefault();
               eventInstance.returnValue = false;
               return false;
            }
         } //filterOut
      --></script>
   </head>
<body">

<textarea id="tarea" onkeypress="counter(event, 150);"></textarea>
<div id="output" />

</body>
</html>



此解决方案显示了如何输出值,以及在超出限制时如何防止输入更多字符.但是,允许使用退格键(并且永远不会阻止删除操作).

—SA



This solution shows how to output value, and how to prevent entering more characters if the limit it exceeded. However, backspace is allowed (and delete is never blocked).

—SA


这篇关于文字区域html控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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