首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript with方法有关问题,求帮助

2012-08-01 
javascript with方法问题,求帮助formtabletrth注册表单/th/trtrtddiv用户名/divdiv

javascript with方法问题,求帮助
<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未定义,有人知道为什么吗?

[解决办法]
inputColor(document.forms[0].user)

热点排行