如何由首字母来确定文本框的输入长度?
例如:首字母是A‘只能输入5位
      首字母是B‘只能输入6位
      首字母是C‘只能输入7位

解决方案 »

  1.   

    onchange时候或者onfocus的时候就获取他限制
      

  2.   

    <input type="text" maxlength="3" onfocus="getMaxLength(this)">
    <script>
    function getMaxLength(input){
    alert("length : " + input.getAttribute("maxlength"));
    }
    </script>
      

  3.   

    <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'>
      

  4.   

    如果要在PHP页面处理,可通AJAX,用正则来判断