A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 陈汉维 中级黑马   /  2012-7-12 11:59  /  2320 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

<form>
        <table>
            <tr>
                <th>注册表单</th>
        </tr>
        <tr>
                <td>
                    <div>用户名</div>
                <div><input type="text" name="user" /></div>
                <div class="errorinfo">用户名错误</div>
                <div>用户名必须是4-6位,由字母(a-z),数字(0-9),下划线(_)组成</div>
            </td>
        </tr>
    </table>
</form>

<script type="text/javascript">
function inputColor(input)
{
        input.className = "norm";
        input.onfocus = function()
        {
                this.className = "focus";
        }
}

window.onload = function()
{
        document.forms[0].inputColor(user);
        /*
        with(document.forms[0])
        {
                inputColor(user);
        }
        */
}
</script>

为什么用
with(document.forms[0])
{
        inputColor(user);
}
可以正常运行。
而用document.forms[0].inputColor(user);
却提示user不存在,有人知道为什么吗?{:soso_e109:}求帮助

2 个回复

倒序浏览
错了。是页面提示user未定义,有人知道为什么吗?
回复 使用道具 举报
正确答案:inputColor(document.forms[0].user);
被自己误导了。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马