<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
</style> 
<title></title>
</head>
<body>
<input type="text" id="text" onkeyup="text()" />
<script type="text/javascript">
function text(){
var text = document.getElementById("text").value;
document.getElementById("text").value = text.substr(0,10);
}
</script>
</body>
</html>
为什么改成这样就不行了?text = text.substr(0,10);

解决方案 »

  1.   

    什么叫不行了?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <style type="text/css">
    </style> 
    <title></title>
    </head>
    <body>
    <input type="text" id="text" onkeyup="text()" />
    <script type="text/javascript">
                function text(){
                        var text = document.getElementById("text").value;
    text = text.substr(0,10)
                        document.getElementById("text").value = text;
                }
    </script>
    </body>
    </html>