为什么在<input type="text"/>中
当属性onkeypress="return false;"会令到输入无效
<script>
function ignore(t){if(t.value.length<5)return true;return false;}
</script>
<input type="text" length="20" onkeypress="return ignore(this);"/>

解决方案 »

  1.   

    return false后取消了事件的默认行为, 即没有等于没有按键的行为
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <script>
    function ignore(t){
    if(t.value.length<5) return true;
    else return false;
    }
    </script>
    <input type="text" size="20" onkeypress="return ignore(this);"/>
      

  2.   

    肯定会有个原理的 是不是跟js的event冒泡原理一样?