如何由首字母来确定文本框的输入长度? 如何由首字母来确定文本框的输入长度?例如:首字母是A‘只能输入5位 首字母是B‘只能输入6位 首字母是C‘只能输入7位 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 onchange时候或者onfocus的时候就获取他限制 <input type="text" maxlength="3" onfocus="getMaxLength(this)"><script>function getMaxLength(input){ alert("length : " + input.getAttribute("maxlength"));}</script> <script laguage="javascript">function test(obj){ firstIndex = obj.substr(0,1); maxLeng = firstIndex.charCodeAt()-60; if(obj.length > maxLeng){ alert('以'+firstIndex+'开头,只能输入'+maxLeng+'位'); document.getElementById('test').value = obj.substr(0,maxLeng); }}</script><input type="text" onkeyup="test(this.value)" id='test'> 如果要在PHP页面处理,可通AJAX,用正则来判断 foreach多层嵌套的问题,求解~! 开发CMS有经验的人来交流下,内容表要不要分成主表和附表 高分啊!!用 CURL 做的登录 登录到目标站 可是为什么 做出来的 SESSION和 不一样呢 php获取客户端MAC和IP地址 js代码嵌入失败 单例模式的写法 --一段php代码的疑惑 php里的html代码如何解释? PHP 怎么保护资源不被下载? PHP学习交流群,200人高级群:66589844 新群欢迎新手加入 防止同一用户在同一时间登录,大家有什么好办法? php无法实例化类,求大神支招 看看大家对jquery的看法!!!!! 是数据库没有配置好吗?
<script>
function getMaxLength(input){
alert("length : " + input.getAttribute("maxlength"));
}
</script>
function test(obj)
{
firstIndex = obj.substr(0,1);
maxLeng = firstIndex.charCodeAt()-60;
if(obj.length > maxLeng){
alert('以'+firstIndex+'开头,只能输入'+maxLeng+'位');
document.getElementById('test').value = obj.substr(0,maxLeng);
}
}
</script><input type="text" onkeyup="test(this.value)" id='test'>