我想在选中该输入框,向里面输入内容时,框内的背景颜色变为红色,下面红色标记的部分在其他的文件中可以运行出来,但是在这里就有错,请大家帮忙看看,多谢了。  
代码如下:
<html>
<head>
<title> getelementid </title>
<script>
 function check(){
   alert(document.getElementById("userid").value);
   alert(document.getElementById("ageid").value);
   alert(document.forms[0].userid.value+" "+document.forms[0].ageid.value);
 }
 function setBck(x)
 {
  alert("enter");
  document.getElementById(x).style.background = "red";
 }
</script>
</head>
<body>
 <form>
   name:<input type = "text" name = "user" id = "userid" onFocus = setBck(userid)/><br/>
   age:<input type = "text" name = "age" id = "ageid" />
   <input type = "button" value = "check" onclick = "check()" />
 </form>
</body>
</html>

解决方案 »

  1.   


    <input type = "text" name = "user" id = "userid" onFocus ="setBck('userid');" />这样试试 。
      

  2.   

     name:<input type = "text" name = "user" id = "userid" onFocus = "setBck(this.id)"/><br/>
      

  3.   

    <input type = "text" name = "user" id = "userid" onFocus = “setBck(this.id)”/><br/>
      

  4.   

    <html>
    <head>
    <title> getelementid </title>
    <script>
     function check(){
      alert(document.getElementById("userid").value);
      alert(document.getElementById("ageid").value);
      alert(document.forms[0].userid.value+" "+document.forms[0].ageid.value);
     }
     function setBck(x)
    {
    alert("enter");
    document.getElementById(x).style.background = "red";
    }</script>
    </head>
    <body>
     <form>
      name:<input type = "text" name = "user" id = "userid" onFocus = "this.style.background='red'" /><br/>
      age:<input type = "text" name = "age" id = "ageid" />
      <input type = "button" value = "check" onclick = "check()" />
     </form>
    </body>
    </html>
      

  5.   

    十分感谢大家,问题解决了
    onFocus = "setBck(this.id)"
    onFocus = "this.style.background='red'"
    都可以的
      

  6.   

    十分感谢大家,问题解决了
    onFocus = "setBck(this.id)"
    onFocus = "this.style.background='red'"都可以的