gpt4 book ai didi

html - 如何使用 Razor 引擎在 View 中为 TextAreaFor 添加最大长度

转载 作者:技术小花猫 更新时间:2023-10-29 12:29:00 24 4
gpt4 key购买 nike

我在使用 Razor 引擎实现的 View 中有一个 TextArea() 控件。

@Html.TextArea("EventNature",new { style = "width: 200px; height: 100px;" })

如何设置此控件的 Maxlength 属性?
RazorEngine 中是否有任何内置属性,还是我必须使用脚本?

最佳答案

你可以这样做:

@Html.TextArea("EventNature",new { maxlength=50, // or other value
style = "width: 200px; height: 100px;" })

请注意这是一个 HTML5 属性

maxlength HTML5
The maximum number of characters (Unicode code points) that the user can enter. If it is not specified, the user can enter an unlimited number of characters.

MDN


HTML <5 的 Javascript(使用 jQuery)验证:

$('#EventNature').keypress(function(){
if (this.value.length >= 10) // allowing you to enter only 10 chars.
return false;
});​

DEMO

关于html - 如何使用 Razor 引擎在 View 中为 TextAreaFor 添加最大长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10586007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com