关于html和CSS的问题,如何限定<input type="text" />中 输入内容 的长度,将限定加在CSS中。
原代码 <style type="text/css"> #如何在此限定输入内容长度??? </style> <input type="text" id="search-videos" class="search-field" size="8" value="<%= this.key && this.key.length ? this.key : "" %>" />
原代码 <style type="text/css"> #如何在此限定输入内容长度??? </style> <input type="text" id="search-videos" class="search-field" size="8" value="<%= this.key && this.key.length ? this.key : "" %>" />
答案:css 通过限定宽度 width 设置超出隐藏 overflow 来控制字符显示
input 中通过 maxlength="" 这种限制字符串字数
其他:input的属性maxlength,可以控制输入字符的字数。或者使用js做个控制 input中输入内容的长短是用maxlenght限制的,不用CSS 这个可以通过js实现!
var s = document.getElementById("search-videos");
var lim_len = 10;//限定的长度
s.onkeypress = function() {
var s_str = s.value;
if(s_str.length > lim_len){
return false;
}
} 这啥意思????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? <input id=txtname maxlength=10 name=txtname>
上一个:css定义文字属性问题求解:
下一个:为什么我的css代码 鼠标放到按钮之后就把下面一行的按钮给挤下去了、怎么解决!!!求助???谢谢