asp.net在TextBox上显示最大长度
本文关键字:显示 net TextBox asp | 更新日期: 2023-09-27 18:27:41
我想使用这个漂亮的小代码:http://mimo84.github.io/bootstrap-maxlength/.我对asp.net编程真的很陌生,我不知道如何在我的项目中使用它。我的文本框已经创建,并且MaxLength属性设置为我想要的值。有人能告诉我为什么它不起作用吗。
<asp:TextBox ID="TextBox1" runat="server" MaxLength="20" onfocus="show()"></asp:TextBox>
<script type="text'javascript">
function show(){
$('input[TextBox1]').maxlength();
}
</script>
所需的javascript文件在主文件中被引用!
ref maxlength.js文件
<script src="../bootstrap-maxlength/bootstrap-maxlength.min.js"></script>
<input type="text" class="form-control" maxlength="25" name="alloptions" id="alloptions">
$('input.className').maxlength({
alwaysShow: true,
threshold: 10,
warningClass: "label label-success",
limitReachedClass: "label label-danger",
separator: ' of ',
preText: 'You have ',
postText: ' chars remaining.',
validate: true
});
请参阅此处的演示
假设您有jQuery和引用的maxlength插件,您所需要做的就是将脚本添加到页面中,如下所示:
<script type="text'javascript">$('input[YOUR_FIELD_ID]').maxlength();</script>
从TextBox控件中删除MaxLength属性和在javascitp函数中定义MaxLength,如下所示:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<script type="text/javascript">
$(document).ready(function () {
$("[id*=TextBox1]").maxlength({
alwaysShow: true,
validate: true,
allowOverMax: false,
customMaxAttribute: "100"
});
});
</script>