问题描述
使用 MultiLine TextBox(生成 TextArea)时,设置 MaxLength 属性无效.最好的解决方法是什么?我想用最少的丑陋的 javascript 等获得基本的、预期的功能.只是防止用户输入超过最大数量的字符.
When using a MultiLine TextBox (which generates a TextArea) setting the MaxLength property has no effect. What is the best workaround? I'd like to get basic, intended functionality with minimum of ugly javascript etc. Just prevent user from entering more than max number of characters.
推荐答案
如果你想让用户知道他是否超过了他写的字符数,你可以使用一个附加到 keypress 事件的 javascript 函数.此函数将测试输入的长度,如果达到最大长度,则取消字符渲染.
If you want to let the user know if he exceeded the amount of characters as he writes, you could use a javascript function attached to keypress event. This function would test the length of the input and cancel the character rendering if the maxlenght was reached.
另一种选择是使用 RegularExpressionValidator 控件来验证提交时的输入.
Another option is to use RegularExpressionValidator control to validate the input on submit.
在我看来,第一种选择要好得多.
In my opinion, the first option is much more better.
我没有添加任何代码,因为谷歌充满了各种口味的示例,这是一项非常常见的任务.
I'm not adding any code since google is full of examples for all tastes, this is a very common task.
这里您有一个可能有帮助的示例搜索.
Here you have a sample search that might help.
这篇关于如何为多行文本框设置最大长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)